0

I am trying to automatically set my browser to fullscreen mode.

Here is my jquery Code.

function ActivateFullScreen() {
    var docElm = document.documentElement;
    if (docElm.requestFullscreen) {
        docElm.requestFullscreen();
    } else if (docElm.mozRequestFullScreen) {
        docElm.mozRequestFullScreen();
    } else if (docElm.webkitRequestFullScreen) {
        docElm.webkitRequestFullScreen();
    }
}

// Binding onlick event to my button

$('#triggerFullscreen').click(function () {
    ActivateFullScreen();
});

// None of these works.

$('#triggerFullscreen').click();

$('#triggerFullscreen').trigger('click');

ActivateFullScreen();

//my button

<button id="triggerFullscreen" ></button>

If I manually press the button my browser is set to fullscreen mode. I really have no clue why this is not working.

Tanks and Best regards

Markus

Markus_DE_HH
  • 1,061
  • 3
  • 13
  • 29
  • 3
    it looks like a browser security protection, going full screen outside a user initiated event might be prevented by the browser – Arun P Johny Aug 20 '13 at 13:30
  • check that your binding code is after the button is loaded, put it inside $(document).ready() function. – Farhan Aug 20 '13 at 13:30
  • if the button is dynamic you should use `.on('click'` instead of `.click(` – Ron van der Heijden Aug 20 '13 at 13:31
  • I think as `Arun P Johny` said it not possible to force browser into fullscreen mode. – Jan.J Aug 20 '13 at 13:31
  • I put an alert at the top of your function then attempted to use trigger to call the function and it worked, it may be something security related like stated above –  Aug 20 '13 at 13:32
  • Not sure if you're using it correctly. MDN Docs specify use of this on the – AdityaSaxena Aug 20 '13 at 13:36
  • see http://stackoverflow.com/questions/9454125/javascript-request-fullscreen-is-unreliable – Arun P Johny Aug 20 '13 at 13:38

2 Answers2

1

Yes seems like security constraint

"To prevent embedded content from going fullscreen only embedded content specifically allowed via the allowfullscreen attribute of the HTML iframe element will be able to go fullscreen. This prevents untrusted content from going fullscreen."

for full article https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html

Farhan
  • 752
  • 4
  • 10
0

Simply use $('#triggerFullscreen').trigger('click', true);

ShapCyber
  • 3,382
  • 2
  • 21
  • 27