Ask and store user permission to use full-screen?

5
Apps usually ask permission to use Smartphone features such as microphone, camera ... I wonder if you can do the same on a page so that FullScreen mode is automatically activated whenever the user opens the page, since the same gave permission for the page.

The code below puts the whole document in FullScreen when triggered by some click event by example:

    if (!document.fullscreenElement &&
      !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) {  
    if (document.documentElement.requestFullscreen) {
      document.documentElement.requestFullscreen();
    } else if (document.documentElement.msRequestFullscreen) {
      document.documentElement.msRequestFullscreen();
    } else if (document.documentElement.mozRequestFullScreen) {
      document.documentElement.mozRequestFullScreen();
    } else if (document.documentElement.webkitRequestFullscreen) {
      document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
    }

Is there any way I can request user permission so that my site can use that feature automatically, without depending on a trigger triggered by it?

    
asked by anonymous 03.03.2017 / 20:29

2 answers

2

Well, you can create a link that points to a window in FullScreen mode as follows:

<a href="javascript:void(0);" onClick="window.open('http://www.google.com', '', 
'fullscreen=yes, scrollbars=auto');">Abrir Janela em Full Screen</a>

If you try to do the same automatically, in onload, you are able to receive a "popup block" from the browser that prevents the window from opening automatically:

<body onLoad="window.open('http://www.google.com', '', 'fullscreen=yes, scrollbars=auto'); window.opener=null; window.close(); return false;">

From Chrome 15, you can use the Full Screen API that opens the entire screen (not a window) in Full Screen. See the demo .

But it can not be done without user interaction, to avoid malicious uses . That is, the user needs to click or press a key to invoke full-screen mode.

I find it difficult to circumvent this restriction because it is something inherent in the HTML 5 specification.

See also question .

    
11.03.2017 / 23:47
2

Unfortunately for security reasons, specifically chrome disables automation in fullscreen mode, you need a prior permission from the user to enable it. I used this code to trigger fullscreen mode

function requestFullScreen(element) {
// Supports most browsers and their versions.
var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;

 if (requestMethod) { // Native full screen.
    requestMethod.call(element);
 }else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
    var wscript = new ActiveXObject("WScript.Shell");
    if (wscript !== null) {
        wscript.SendKeys("{F11}");
    }
 }
}

I made tests by putting the following code in the functions document.onload , document.ready .

 var elem = document.body; 
 requestFullScreen(elem); 

I get the following browser response in the console:

  

Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture.   requestFullScreen @ main.html: 20

Sources:
How to open a web page automatically in full screen mode
Chrome fullscreen API
Run website in fullscreen mode

    
13.03.2017 / 23:32