Skip to content

Instantly share code, notes, and snippets.

@tristaaan
Last active August 29, 2015 14:08
Show Gist options
  • Save tristaaan/a344e845df7dd1f152cb to your computer and use it in GitHub Desktop.
Save tristaaan/a344e845df7dd1f152cb to your computer and use it in GitHub Desktop.
function toggleFullscreen(){
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement &&
!document.webkitFullscreenElement &&
!document.msFullscreenElement ) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
}
else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment