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();
}
}
}