IOS10全屏safari Javascript

时间:2017-03-26 02:43:11

标签: javascript jquery html ios safari

当用户点击网站上的按钮时,我正试图让div全屏显示。

唯一的问题是,除IOS上的Safari外,每个浏览器似乎都想工作。

为了能够全屏播放,我需要做什么?我尝试过研究,却找不到任何东西。

继承我目前的代码:

<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>

1 个答案:

答案 0 :(得分:4)

正如很多帖子所提到的,在Safari和Chrome中无法在IOS&gt; = 10上切换到全屏。这是因为不支持Fullscreen API:

你有两种可能的技巧: