Cristocea Costel
Cristocea Costel

Reputation: 93

JavaScript Fullscreen API plugin

I've found a plugin called screenfull.js and I'm wondering if it's possible to automatically open the page in fullscreen without clicking on a button. This is an example of code for making the page fullscreen :

document.getElementById('#button').addEventListener('click', function() {
if ( screenfull ) {
    screenfull.request();
} else {
    // Ignore or do something else
}

});

Upvotes: 2

Views: 1843

Answers (3)

Ema4rl
Ema4rl

Reputation: 588

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...

Upvotes: 1

Bergi
Bergi

Reputation: 664195

No, that is not possible. The requestFullScrenn() must be triggered by a direct user action (like a click) for security considerations. It's just the same as with popups.

Read https://wiki.mozilla.org/Security/Reviews/Firefox10/CodeEditor/FullScreenAPI and maybe https://wiki.mozilla.org/Gecko:FullScreenAPI for reference.

Upvotes: 1

Barrie Reader
Barrie Reader

Reputation: 10715

Using their demo, you could just run the request on window load:

e.g.

window.onload = function() {
    screenfull.request( $('#container')[0] );
};

[edit]
You could also run this with jQuery document ready...

E.g.

$(document).ready(function() {
    screenfull.request( $('#container')[0] );
});

Upvotes: 1

Related Questions