jQuery: Open/request Fullscreen browser on load?

六眼飞鱼酱① 提交于 2019-12-24 17:53:20

问题


I have a page with a div #container which I would like to have go into full screen mode (or at least request to go into full screen mode) on supported browsers.

I downloaded this plugin

and although the example all show using a button to enter fullscreen, I'd like to do it on load. I tried:

$(window).load(function() {
        if($.support.fullscreen){
            $('#container').fullScreen();
        }
    });

It passes the support test (Chrome 28) but nothing happens. What am I missing?


回答1:


It would seem, after further research, that the fullscreen API can only be activated via user interaction for security reasons. If anyone knows otherwise, please feel free to post.




回答2:


I use a trick...
        I listen for any click on the body to activate.
Eg:

$('body').on('click', '*', function() {
        screenfull.request();
    });
N.B.: It does not track buttons (e.t.c) that already have event handlers...

来源:https://stackoverflow.com/questions/15890928/jquery-open-request-fullscreen-browser-on-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!