admin管理员组文章数量:1332382
I have a problem for a fullscreen mode in a webapp on iOS mobile device (iPhone and IPad, all versions).
I have a button which call a toggle fullscreen function. This function work on all devices other than iOS.
My function :
function toggleFullScreen(e) {
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement && !window.navigator.standalone) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
$('body').css({'height': screen.height});
fullSreen = true;
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}else if(document.cancelFullScreen){
document.cancelFullScreen();
}
$('body').css({'height': 'auto'});
fullSreen = false;
}
}
It does not work on Safari, Chrome and Firefox on iOS mobile/iPad, but the function is call (i try it with some alert message). I do not understand why, thx in advance !
I have a problem for a fullscreen mode in a webapp on iOS mobile device (iPhone and IPad, all versions).
I have a button which call a toggle fullscreen function. This function work on all devices other than iOS.
My function :
function toggleFullScreen(e) {
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement && !window.navigator.standalone) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
$('body').css({'height': screen.height});
fullSreen = true;
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}else if(document.cancelFullScreen){
document.cancelFullScreen();
}
$('body').css({'height': 'auto'});
fullSreen = false;
}
}
It does not work on Safari, Chrome and Firefox on iOS mobile/iPad, but the function is call (i try it with some alert message). I do not understand why, thx in advance !
Share asked Aug 16, 2017 at 14:03 ErosEros 511 silver badge2 bronze badges 1- stackoverflow./a/65516223/372347 shows that arbitrary html elements can't currently go fullscreen. Unless the element is a video it won't work on ios. – Todd Commented Aug 7, 2021 at 13:55
2 Answers
Reset to default 3Please try the below code. It's working fine in my system in all browsers of the iPhone.
HTML
<div class="video-banner-div">
<video class="video-bg" id="home_banner_video" playsinline="" autoplay="true" preload="">
<source src="url_of_your_video.mp4" type="video/mp4">
</video>
</div>
JS
vid = $('.video-banner-div video').get(0); // get the element of video tag
$(".full-screen-icon").on("click", function () {
// on click of the button call the toggle function
toggleFullScreen();
});
function toggleFullScreen() {
if (vid.requestFullScreen) {
vid.requestFullScreen();
} else if (vid.webkitRequestFullScreen) {
vid.webkitRequestFullScreen();
} else if (vid.mozRequestFullScreen) {
vid.mozRequestFullScreen();
} else if (vid.msRequestFullscreen) {
vid.msRequestFullscreen();
} else if (vid.webkitEnterFullscreen) {
vid.webkitEnterFullscreen(); //for iphone this code worked
}
}
You can verify at http://caniuse./fullscreen that iOS Safari does not offer a API for fullscreen, check this asnwer for more information Full screen api HTML5 and Safari (iOS 6) . But html video elements can go fullscreen.
Take a look at https://brad.is/coding/BigScreen/ , is a good lib to handle fullscreen events.
本文标签:
版权声明:本文标题:javascript - Fullscreen toggle doesn't work on iOS mobiletablet (Safari, Chrome and Firefox) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742293535a2448266.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论