10
我有一個YouTube視頻embedded on my site using an iFrame。我想用the API暫停視頻,但在Chrome中我得到一個錯誤:如何在Chrome和Firefox中使用YouTube iFrame API?
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來訪問我頁面的主框架?
謝謝!
我仍然使用JavaScript Player API嵌入iframe的錯誤。我甚至用他們的瀏覽器在他們的遊樂場裏試了他們的代碼 – Josh 2013-08-27 22:42:07