Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arturparkhisenko/53e7395f4ba21a617d26 to your computer and use it in GitHub Desktop.
Save arturparkhisenko/53e7395f4ba21a617d26 to your computer and use it in GitHub Desktop.
Fullscreen API, fullscreenchange
var inFullScreen = document.fullscreenEnabled || document.fullscreenElement ||
window.fullScreen || document.webkitIsFullScreen || document.msFullscreenEnabled;
if (inFullScreen) {
//do something..
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
} else {
//do something..
var docElement = document.documentElement;
if (docElement.requestFullscreen) {
docElement.requestFullscreen();
} else if (docElement.mozRequestFullScreen) {
docElement.mozRequestFullScreen();
} else if (docElement.webkitRequestFullscreen) {
docElement.webkitRequestFullscreen();
} else if (docElement.msRequestFullscreen) {
docElement.msRequestFullscreen();
}
}
// other
document.addEventListener("fullscreenchange", function () {
fullscreenState.innerHTML = (document.fullscreen)? "" : "not ";
}, false);
document.addEventListener("mozfullscreenchange", function () {
fullscreenState.innerHTML = (document.mozFullScreen)? "" : "not ";
}, false);
document.addEventListener("webkitfullscreenchange", function () {
fullscreenState.innerHTML = (document.webkitIsFullScreen)? "" : "not ";
}, false);
document.addEventListener("msfullscreenchange", function () {
fullscreenState.innerHTML = (document.msFullscreenElement)? "" : "not ";
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment