Tengo un video de YouTube embedded on my site using an iFrame. Quiero usar the API para pausar el video, pero en Chrome consigo un error:¿Cómo se usa la API iFrame de YouTube en Chrome y 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.
En Firefox (3.6) me sale este error:
Permission denied for <http://www.youtube.com> to call method Location.toString on <http://subdomain.example.com>.
He intentado poner el iFrame yo mismo o agregarlo con la API. De cualquier manera, el jugador entra, pero no tengo control de API sobre él.
Aquí está la parte correspondiente de mi código:
<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>
¿Cómo consigo los navegadores para permitir el acceso a YouTube marco flotante de marco principal de mi página?
Gracias!
Recibo el error utilizando JavaScript Player API para incrustaciones iframe. Incluso probé su código en su patio de recreo con su navegador. – Josh