【发布时间】:2011-06-24 13:10:46
【问题描述】:
我有一个 YouTube 视频 embedded on my site using an iFrame。我想使用the API 暂停视频,但在 Chrome 中出现错误:
Unsafe JavaScript attempt to access frame with URL http://subdomain.example.com/ from frame with URL http://www.youtube.com/embed/KmtzQCSh6xk?enablejsapi=1&origin=http://subdomain.example.com. Domains, protocols and ports must match.
在 Firefox (3.6) 中出现此错误:
Permission denied for <http://www.youtube.com> to call method Location.toString on <http://subdomain.example.com>.
我尝试将 iFrame 放入自己或使用 API 添加。无论哪种方式,播放器都可以进入,但我无法通过 API 控制它。
这是我的代码的相关部分:
<div id="player"></div>
<script type="text/javascript">
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '433',
width: '731',
videoId: 'KmtzQCSh6xk'
});
}
$("#pause_button").click(function(){
alert("Pausing " + player);//is undefined :(
player.pauseVideo();
});
</script>
如何让浏览器允许 YouTube iFrame 访问我页面的主框架?
谢谢!
【问题讨论】:
标签: firefox iframe google-chrome youtube youtube-api