javascript 删除 youtube iframe api 控制台错误的方法 - 在 chrome 控制台中“阻止了一个带有原点的框架......”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16941139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 06:33:06  来源:igfitidea点击:

Methods of removing the youtube iframe api console error - "blocked a frame with origin..." in chrome console

javascriptyoutubeyoutube-api

提问by styler

I'm using the youtube iframe api and get the following console error relating to the blocking of a frame with origin http://www.youtube.com. Was wondering if anyone can explain why this error is only appearing in the chrome console and if there are any ways to prevent this happening?

我正在使用 youtube iframe api 并收到以下与阻止来自http://www.youtube.com的框架有关的控制台错误。想知道是否有人可以解释为什么这个错误只出现在 chrome 控制台中,是否有任何方法可以防止这种情况发生?

Error:

错误:

Blocked a frame with origin "http://www.youtube.com" from accessing a frame with origin "http://youtubetest.appspot.com". Protocols, domains, and ports must match.

阻止了来源为“ http://www.youtube.com”的框架访问来源为“ http://youtubetest.appspot.com”的框架。协议、域和端口必须匹配。

回答by Wulf Solter

I had a similar error where the JS error was:

我有一个类似的错误,其中 JS 错误是:

Blocked a frame with origin "https://www.youtube.com" from accessing a frame with origin "http://www.yourdomain.com". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocol/Protocols must match, YouTube has CORS (Cross Origin Resource Sharing) enabled to allow across domains.

阻止了来源为“ https://www.youtube.com”的框架访问来源为“ http://www.yourdomain.com”的框架。请求访问的帧具有“https”协议,被访问的帧具有“http”协议。协议/协议必须匹配,YouTube 启用了 CORS(跨域资源共享)以允许跨域。

Try getting rid of the https://in your YouTube iframe tag?

尝试删除https://YouTube iframe 标签中的 ?

You could also take a look at your closing iframe tags. Iframe tags are not singleton tags and must end with a </iframe>and not a />.

您还可以查看关闭 iframe 标签。iframe 标签不是单例标签,必须以 a</iframe>而不是 a结尾/>

回答by Andy

It seems that today, using the protocol-free "//youtube.com" URL that YouTube puts IN THEIR OWN EMBED CODE SNIPPET TOOL is throwing protocol matching errors. (sigh) This worked fine earlier this week.

似乎今天,使用 YouTube 放入他们自己的嵌入代码片段工具中的无协议“//youtube.com” URL 正在抛出协议匹配错误。(叹气)这在本周早些时候工作得很好。

If I add the https: to the embed URL it stops throwing errors and the iframe JS API works. It will continue to throw your "Blocked a frame with origin ..." error, but the JS API will function as expected.

如果我将 https: 添加到嵌入 URL,它会停止抛出错误并且 iframe JS API 工作。它会继续抛出您的“Blocked a frame with origin ...”错误,但 JS API 将按预期运行。