Skip to content

Instantly share code, notes, and snippets.

@roz0n
Created July 3, 2017 02:41
Show Gist options
  • Save roz0n/c42d4cbfc9b5cdedc3aa180208b3746b to your computer and use it in GitHub Desktop.
Save roz0n/c42d4cbfc9b5cdedc3aa180208b3746b to your computer and use it in GitHub Desktop.
JavaScript Fullscreen API
// Find the right method, call on correct element
function launchFullscreen(element) {
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if(element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}
// Launch fullscreen for browsers that support it!
// Call these commands from console, but you might need to hard code these first.
//launchFullScreen(document.documentElement); // the whole page
//launchFullScreen(document.getElementById("videoElement")); // any individual element
// Whack fullscreen
function exitFullscreen() {
if(document.exitFullscreen) {
document.exitFullscreen();
} else if(document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if(document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
// Cancel fullscreen for browsers that support it!
//exitFullscreen();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment