iOS10全屏野生动物园Javascript [英] IOS10 fullscreen safari Javascript

查看:126
本文介绍了iOS10全屏野生动物园Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击网站上的按钮时,我正在尝试使div进入全屏显示状态.

I'm trying to make a div go fullscreen, when a user clicks a button on a website.

唯一的是,除了IOS上的Safari之外,每个浏览器似乎都希望工作.

Only thing is, every browser seems to want to work except for Safari on IOS.

要使其全屏显示,我需要做什么?我曾尝试研究,但找不到任何东西.

What will I need to do to be able to make it fullscreen? I've tried researching, but unable to find anything.

这里是我当前的代码:

<script type="text/javascript">
function goFullscreen(id) {
    var element = document.getElementById(id); 

    var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
        (document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
        (document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
        (document.msFullscreenElement && document.msFullscreenElement !== null);

    var docElm = document.documentElement;
    if (!isInFullScreen) {
        if (element.requestFullscreen) {
            element.requestFullscreen();
        } else if (element.mozRequestFullScreen) {
            element.mozRequestFullScreen();
        } else if (element.webkitRequestFullScreen) {
           element.webkitRequestFullScreen();
        } else if (element.msRequestFullscreen) {
            element.msRequestFullscreen();
        }
    } else {
        if (document.exitFullscreen) {
            document.exitFullscreen();
        } else if (document.webkitExitFullscreen) {
            document.webkitExitFullscreen();
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        } else if (document.msExitFullscreen) {
            document.msExitFullscreen();
        }
    }
}
</script>

推荐答案

正如许多文章所述,在Safari和Chrome中,无法在IOS> = 10上切换到全屏模式.这是因为不支持全屏API:

As mentioned on many posts, there is no way to switch to fullscreen on IOS >=10 in Safari and Chrome. It is because the Fullscreen API is not supported:

  • Can I Use Full Screen API
  • open webpage in fullscreen in Safari on iOS
  • Full screen api HTML5 and Safari (iOS 6)

您有两个可能的窍门:

  • 如果您切换到风景.但是您不能强迫他,iOS Chrome无法做到这一点(防止iOS中的方向更改Safari ).
  • 如果您的网页是在网络应用程序中导出的,并且您正确配置了元界面(
  • if you switch to landscape. But you can not force him and iOS Chrome can't do this (Prevent orientation change in iOS Safari).
  • if your webpage is exported in a web app and you configure the meta balises correctly (Optimizing Full Screen Mobile Web App for iOS).

这篇关于iOS10全屏野生动物园Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆