在iOS中使用Javascript的FullScreen iFrame [Safari]

时间:2017-11-22 22:52:20

标签: javascript html ios safari fullscreen

我设置了全屏功能:

function setUpFullScreen() {
    document.cancelFullScreen = document.webkitCancelFullScreen || document.mozCancelFullScreen || document.cancelFullScreen;
    document.body.requestFullScreen = document.body.webkitRequestFullScreen || document.body.mozRequestFullScreen || document.body.requestFullScreen;
    document.onfullscreenchange = document.onfullscreenchange || document.onwebkitfullscreenchange || document.onmozfullscreenchange;
    if (document.addEventListener) {
        document.addEventListener('webkitfullscreenchange', fullscreenChangeHandler, false);
        document.addEventListener('mozfullscreenchange', fullscreenChangeHandler, false);
        document.addEventListener('fullscreenchange', fullscreenChangeHandler, false);
        document.addEventListener('MSFullscreenChange', fullscreenChangeHandler, false);
    }
}

使用以下方法切换FullScreen:

function toggleFullScreen() {
    if (isFullScreen()) {
        trace("Exiting fullscreen.");
        document.querySelector("svg#fullscreen title").textContent = "Enter fullscreen";
        document.cancelFullScreen();
    } else {
        trace("Entering fullscreen.");
        document.querySelector("svg#fullscreen title").textContent = "Exit fullscreen";
        document.body.requestFullScreen();
    }
}

检查全屏:

function isFullScreen() {
    return !!(document.webkitIsFullScreen || document.mozFullScreen || document.isFullScreen);
}

切换全屏适用于Chrome,Safari,Firefox(桌面版)以及Android版Chrome。但是,不在Safari和Chrome上工作。我在safari上看到以下错误:

TypeError: document.body.requestFullScreen is not a function. (In 'document.body.requestFullScreen()', 'document.body.requestFullScreen' is undefined)

如何使用javascript在iOS上完成全屏功能?

仅供参考:我的代码改编为https://appr.tc/ https://github.com/webrtc/apprtc/blob/master/src/web_app/js/appcontroller.js

1 个答案:

答案 0 :(得分:0)

使用:

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
HTML文件中的

对我有用。