这里我有另一个问题,这次是关于 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>
请不要介意\",它是用PHP渲染的,所以它只是为了转义,而且,视频正在播放,所以没有大错误:)
让我烦恼的是,每次我请求视频时,我都会在控制台中看到这条消息:不安全的 JavaScript 尝试使用 URL 访问框架
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。域、协议和端口必须匹配。
我想解决这个问题,所以我看不到该消息。我知道这并不是一件大事,但我现在喜欢如何在我的网站上获得一个 youtube 播放器而不会看到上面的警告。
希望你们能帮助我!
编辑:这是输出:
<div id="YTcontainer_502513c7ebc1b"> </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>