javascript 加载文档时的全屏浏览器窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10352236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 09:34:50  来源:igfitidea点击:

full-screen browser window on load document

javascriptjquerybrowserdom-events

提问by itsazzad

How can I full-screen browser window after loading the page? I have used code like below in jQuery but its working only using the event click; but I want that to be worked on load.

加载页面后如何全屏浏览器窗口?我在 jQuery 中使用过类似下面的代码,但它只能使用事件click;但我希望在负载上工作。

jQuery(document).ready(function($) {
    function fullScreen(){
            var docElm = document.documentElement;
            if (docElm.requestFullscreen) {
                //alert("requestFullscreen");
                docElm.requestFullscreen();
            }
            else if (docElm.mozRequestFullScreen) {
                //alert("mozRequestFullScreen");
                docElm.mozRequestFullScreen();
            }
            else if (docElm.webkitRequestFullScreen) {
                //alert("webkitRequestFullScreen");
                docElm.webkitRequestFullScreen();
            }

    }
});

回答by Fabrizio Calderan

from https://wiki.mozilla.org/Gecko:FullScreenAPI#Suggested_UA_Policy

来自https://wiki.mozilla.org/Gecko:FullScreenAPI#Suggested_UA_Policy

..requestFullScreen while the window is already in the full-screen state is approved. Otherwise, requestFullScreen outside a user action(e.g. a non-synthesized input event handler) is denied.

..requestFullScreen 当窗口已经处于全屏状态时被批准。否则,拒绝用户操作(例如,非合成输入事件处理程序)之外的requestFullScreen

so it's not possible force a fullscreen if it's not triggered by a user action

因此,如果不是由用户操作触发,则不可能强制全屏显示