Youtube Unsafe JavaScript 尝试使用 URL 访问框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11902260/
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-26 14:43:15  来源:igfitidea点击:

Youtube Unsafe JavaScript attempt to access frame with URL

javascriptyoutubeyoutube-apiyoutube-javascript-api

提问by TheatreOfSouls

Here I am with another question, this time about the youtube API. I'm using this code to get a youtube player:

我还有另一个问题,这次是关于 youtube API。我正在使用此代码来获取 youtube 播放器:

<div id=\"youtubeVideoContainer\"></div><script type=\"text/javascript\">
                        //Load player api asynchronously.
                        var tag = document.createElement('script');
                        tag.src = \"//www.youtube.com/player_api\";
                        var firstScriptTag = document.getElementsByTagName('script')[0];
                        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

                        var player;
                        function onYouTubePlayerAPIReady() {
                            player = new YT.Player('youtubeVideoContainer', {
                              height        : \"".$height."\",
                              width         : \"".$width."\",
                              videoId       : \"".$id."\",
                              playerVars    : ".json_encode($this->playerParams)."
                            });
                        }
                    </script>

Please don't mind the \", it is rendered in PHP, so it's just for escaping, also, the video is playing, so no major errors :)

请不要介意\",它是用PHP呈现的,所以它只是为了转义,而且视频正在播放,所以没有大错误:)

What does annoy me, is everytime I request a video, I see this message in my console: Unsafe JavaScript attempt to access frame with URL

令我烦恼的是,每次我请求视频时,我都会在控制台中看到此消息:不安全的 JavaScript 尝试使用 URL 访问框架

https://www.socialthisday.com/playwin/admin/content/edit/project_1/home.htmlfrom frame with URL https://www.youtube.com/embed/2UJH9dCtp7w?autohide=1&autoplay=1&controls=0&border&cc_load_policy=0&color&color1&color2&disablekb&enablejsapi=1&egm&fs&hd&iv_load_policy&loop&modestbranding=1&origin=https%3A%2F%2Fwww.socialthisday.com&playerapiid&playlist&rel=0&showinfo=0&showsearch&start&theme&version=3. Domains, protocols and ports must match.

https://www.socialthisday.com/playwin/admin/content/edit/project_1/home.html来自带有 URL 的框架 https://www.youtube.com/embed/2UJH9dCtp7w?autohide=1&autoplay=1&controls=0&border&cc_load_policy=0&color&color1&color2&disablekb&enablejsapi =1&egm&fs&hd&iv_load_policy&loop&modestbranding=1&origin=https%3A%2F%2Fwww.socialthisday.com&playerapiid&playlist&rel=0&showinfo=0&showsearch&start&theme&version=3。域、协议和端口必须匹配。

I would like to fix this so I don't see that message. I know it isn't really a major thing, but I like to now how I can get a youtube player on my site without seeing the warning above.

我想解决这个问题,所以我看不到那条消息。我知道这并不是什么大事,但我喜欢现在如何在我的网站上获得一个 youtube 播放器而不会看到上面的警告。

Hopefully you guys can help me out!

希望大家帮帮我!

EDIT: This is the output:

编辑:这是输出:

<div id="YTcontainer_502513c7ebc1b">&nbsp;</div>
                        <script type="text/javascript">
                            //Load player api asynchronously.
                            var tag = document.createElement('script');
                            tag.src = "//www.youtube.com/iframe_api";
                            var firstScriptTag = document.getElementsByTagName('script')[0];
                            firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

                            var YTplayer_502513c7eb834;                                                        
                            window.onYouTubeIframeAPIReady = function() {
                                YTplayer_502513c7eb834   = new YT.Player("YTcontainer_502513c7ebc1b", {
                                  height        : "200",
                                  width         : "200",
                                  videoId       : "2UJH9dCtp7w",
                                  playerVars    : {"autohide":1,"autoplay":1,"controls":0,"border":"","cc_load_policy":0,"color":"","color1":"","color2":"","disablekb":"","enablejsapi":"","egm":"","fs":"","hd":"","iv_load_policy":"","loop":"","modestbranding":1,"origin":"","playerapiid":"","playlist":"","rel":0,"showinfo":0,"showsearch":"","start":"","theme":"","version":3,"wmode":"opaque"}
                                });
                            }

                            if(window.YT){
                                onYouTubeIframeAPIReady();
                            }
                        </script>

采纳答案by Jeff Posnick

The underlying issue is http://code.google.com/p/chromium/issues/detail?id=17325

根本问题是http://code.google.com/p/chromium/issues/detail?id=17325

Once that's resolved, the warnings in the JavaScript console on pages that use the YouTube iframeembed should go away—certainly for Chrome, and I believe for Safari as well.

一旦解决了这个问题,使用 YouTubeiframe嵌入的页面上 JavaScript 控制台中的警告应该会消失——当然对于 Chrome,我相信对于 Safari 也是如此。

回答by GianFS

check the "Use old embed code"

检查“使用旧的嵌入代码”

it will use <object>tag to embed the video

它将使用<object>标签嵌入视频