在youtube iframe视频上启用全屏

时间:2015-09-25 19:37:07

标签: javascript youtube

我使用以下代码创建iframeyoutubevidéo:

var tag = document.createElement('script');
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// ...

_yt_player = new YT.Player("#myobjectytiframe", {
  height  : 640,
  width   : 480,
  videoId : video_id,
  events  : {
    'onReady': function(){
        _yt_player.playVideo();
        // ENABLE FULLSCREEN
    },
    'onStateChange': function(){},
    'onError': function(){}
  }
});

我想在onReady回调中启用全屏,怎么做?

1 个答案:

答案 0 :(得分:0)

尝试使用html5 api:

document.fullScreen;
 node.requestFullScreen();
 document.cancelFullScreen();