2011-02-10 3 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>. 

:이 오류가 파이어 폭스에서

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를 사용하기를 원하지만 크롬에서 오류가 발생합니다 나 자신 또는 API로 추가. 어느 쪽이든 플레이어가 들어 오지만 API 컨트롤이 없습니다. 나는 유튜브 iframe이 내 페이지의 메인 프레임에 액세스 할 수 있도록 브라우저는 어떻게합니까

<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> 

:

여기 내 코드의 관련 부분이다?

감사합니다.

답변

6
  1. 경고를 무시하십시오. 플레이어는 상관없이 여전히 잘 작동해야합니다.

  2. 최근에 소개 된 JavaScript Player API for iframe embeds을 사용하십시오.

+1

iframe 삽입에 대한 자바 스크립트 플레이어 API를 사용하여 여전히 오류가 발생합니다. 나는 심지어 브라우저로 놀이터에서 코드를 시험해 보았다. – Josh

관련 문제