2011-02-10 6 views
10

私はYouTubeのビデオembedded on my site using an iFrameを持っています。私はiFrameを入れて試してみたChromeとFirefoxでYouTube iFrame APIを使用するにはどうすればよいですか?

Permission denied for <http://www.youtube.com> to call method Location.toString on <http://subdomain.example.com>. 

:私はこのエラーを取得するのFirefoxでは

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. 

(3.6):私は、ビデオを一時停止するthe APIを使用したいが、Chromeで、私はエラーを取得します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が私のページのメインフレームにアクセスできるようにするには、ブラウザを入手するにはどうすればよいですか?

ありがとうございます!

答えて

6
  1. これらの警告は無視してください。プレイヤーは関係なく、正常に動作するはずです。

  2. 最近導入されたJavaScript Player API for iframe embedsを使用してください。

+1

iframe埋め込み用のJavaScript Player APIを使用してもエラーが発生します。私は自分のブラウザで自分のコードをプレイグラウンドで試してみました。 – Josh

関連する問題