Skip to content

Instantly share code, notes, and snippets.

@aindong
Last active August 29, 2015 14:17
Show Gist options
  • Save aindong/5c0ffae786b20abd4ec6 to your computer and use it in GitHub Desktop.
Save aindong/5c0ffae786b20abd4ec6 to your computer and use it in GitHub Desktop.
Toggle Fullscreen mode on a webpage
function toggleFullScreen() {
if ((document.fullScreenElement && document.fullScreenElement !== null) ||
(!document.mozFullScreen && !document.webkitIsFullScreen)) {
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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment