Ho un video YouTube embedded on my site using an iFrame. Voglio usare the API per mettere in pausa il video, ma in Chrome ottengo un errore:Come utilizzare l'API iFrame di YouTube in Chrome e 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.
In Firefox (3.6) ottengo questo errore:
Permission denied for <http://www.youtube.com> to call method Location.toString on <http://subdomain.example.com>.
Ho provato a mettere l'iFrame in me stesso o aggiungendolo con l'API. In entrambi i casi, il giocatore entra in gioco, ma non ho alcun controllo API su di esso.
Ecco la parte rilevante del mio codice:
<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>
Come faccio ad avere i browser per consentire al YouTube iFrame per accedere telaio principale della mia pagina?
Grazie!
Ho ancora ricevuto l'errore utilizzando l'API JavaScript Player per incorporamenti iframe. Ho persino provato il loro codice nel loro parco giochi con il loro browser. – Josh