问题
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(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();
}
}
});
回答1:
from 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.
so it's not possible force a fullscreen if it's not triggered by a user action
来源:https://stackoverflow.com/questions/19856794/automatic-browser-full-screen-switch-on-document-load-ready