0

I want when my webpage is loading it will be auto fullscreen without clicking on the body.You can take a look at my website that I want to make a change: TV. When you click it anywhere, it will be fullscreen. But I want to make it automatically fullscreen without click anything. I was wondering if I could use auto click to change onClick on the body? Because using onload nothing happened. Can you help me?

I only use <body onclick="toggleFullScreen()"> in my html document.

And this is the javascript of toggleFullScreen:

function errorHandler() {
   alert('mozfullscreenerror');
}
document.documentElement.addEventListener('mozfullscreenerror', errorHandler, false);

// toggle full screen

function toggleFullScreen() {
  if (!document.fullscreenElement &&    // alternative standard method
      !document.mozFullScreenElement && !document.webkitFullscreenElement) {  // current working methods
    if (document.documentElement.requestFullscreen) {
      document.documentElement.requestFullscreen();
    } else if (document.documentElement.mozRequestFullScreen) {
      document.documentElement.mozRequestFullScreen();
    } else if (document.documentElement.webkitRequestFullscreen) {
      document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
    }
  } else {
    if (document.cancelFullScreen) {
      document.cancelFullScreen();
    } else if (document.mozCancelFullScreen) {
      document.mozCancelFullScreen();
    } else if (document.webkitCancelFullScreen) {
      document.webkitCancelFullScreen();
    }
  }
}
smci
  • 32,567
  • 20
  • 113
  • 146
hendraspt
  • 959
  • 3
  • 19
  • 42
  • It's not possible. See here => [http://stackoverflow.com/questions/11567993/is-possible-automatic-fullscreen-with-html5](http://stackoverflow.com/questions/11567993/is-possible-automatic-fullscreen-with-html5) – lshettyl Mar 19 '15 at 06:34

2 Answers2

0

put it like this before body tag,

<script>
$(document).ready(function(){
toggleFullScreen();
});
</script>
Ayyanar G
  • 1,545
  • 1
  • 11
  • 24
0

If you want to stick to javascript, then try this.

<script type="text/javascript">
window.onload = maxWindow;

function maxWindow() {
    window.moveTo(0, 0);


    if (document.all) {
        top.window.resizeTo(screen.availWidth, screen.availHeight);
    }

    else if (document.layers || document.getElementById) {
        if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
}

</script> 
callback
  • 3,981
  • 1
  • 31
  • 55