admin管理员组文章数量:1404922
I'm running into a bug when making the YouTube player to go into fullscreen mode via JavaScript.
I have a button that when it's clicked, it triggers the YT.Player.playVideo()
method, while at the same time asking the containing iframe to go into fullscreen as follows:
thisVid = document.getElementById("ytIframe");
if (thisVid.requestFullscreen) {
thisVid.requestFullscreen();
}
else if (thisVid.msRequestFullscreen) {
thisVid.msRequestFullscreen();
}
else if (thisVid.mozRequestFullScreen) {
thisVid.mozRequestFullScreen();
}
else if (thisVid.webkitRequestFullScreen) {
thisVid.webkitRequestFullScreen();
}
(This is using Stack Overflow answers here and here)
The iframe successfully takes up the screen, however, the YouTube player doesn't know it's in fullscreen mode because the fullscreen button in the bottom-right is still available:
When I click it, it stays in fullscreen, and it tells me "youtube is now fullscreen":
This is a problem because the user needs to click the button twice to be able to exit fullscreen mode. Is there a way to tell the youtube player to go fullscreen, instead of just telling its containing iframe to do so?
I'm running into a bug when making the YouTube player to go into fullscreen mode via JavaScript.
I have a button that when it's clicked, it triggers the YT.Player.playVideo()
method, while at the same time asking the containing iframe to go into fullscreen as follows:
thisVid = document.getElementById("ytIframe");
if (thisVid.requestFullscreen) {
thisVid.requestFullscreen();
}
else if (thisVid.msRequestFullscreen) {
thisVid.msRequestFullscreen();
}
else if (thisVid.mozRequestFullScreen) {
thisVid.mozRequestFullScreen();
}
else if (thisVid.webkitRequestFullScreen) {
thisVid.webkitRequestFullScreen();
}
(This is using Stack Overflow answers here and here)
The iframe successfully takes up the screen, however, the YouTube player doesn't know it's in fullscreen mode because the fullscreen button in the bottom-right is still available:
When I click it, it stays in fullscreen, and it tells me "youtube. is now fullscreen":
This is a problem because the user needs to click the button twice to be able to exit fullscreen mode. Is there a way to tell the youtube player to go fullscreen, instead of just telling its containing iframe to do so?
Share Improve this question edited May 23, 2017 at 12:01 CommunityBot 11 silver badge asked Sep 3, 2014 at 2:39 M -M - 28.6k12 gold badges54 silver badges93 bronze badges 3- remove the control button can be a solution. – mpgn Commented Sep 3, 2014 at 8:42
-
I'd like to, but the only option is
controls: 0
and that removes volume, play/pause, and the seek bar. I would hate to leave the user without access to all those elements. – M - Commented Sep 3, 2014 at 18:00 - you can make your custom button play/pause/volume – mpgn Commented Sep 3, 2014 at 19:57
1 Answer
Reset to default 4Because the YouTube player actually exists inside an iFrame, when you use the javascript fullscreen API you're full screening the iframe, not the player. So as far as it's concerned it is not full screen. The only way to get the player to go to full screen mode is for the user to click the button manually (this is a legacy requirement, as the iframe could still contain the Flash player, and Flash has security measures to prevent programmatic fullscreening). For now your only solution is a custom control bar (and even then you won't be full screening the player, but just its container ... but at least you'd have control over what the buttons do).
本文标签: htmlMaking YouTube player go fullscreen via JavaScriptStack Overflow
版权声明:本文标题:html - Making YouTube player go fullscreen via JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744874948a2629859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论