HTML DOM exitFullscreen() Method
Example
Open the HTML page in fullscreen mode, and close it with a click of a button:
/* Get the documentElement (<html>) to display the page in fullscreen */
var elem = document.documentElement;
/* View in fullscreen */
function openFullscreen() {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { /* Firefox */
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen)
{ /* Chrome, Safari and Opera */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen)
{ /* IE/Edge */
elem.msRequestFullscreen();
}
}
/*
Close fullscreen */
function closeFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) { /* Firefox */
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen)
{ /* Chrome, Safari and Opera */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE/Edge */
document.msExitFullscreen();
}
}
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The exitFullscreen() method cancels an element in fullscreen mode.
Note: This method requires specific prefixes to work in different browsers (see Browser Support below).
Tip: Use the requestFullscreen() method to open an element in fullscreen mode.
Browser Support
The numbers in the table specify the first browser version that fully supports the method. Note: Each browser requires a specific prefix (see parentheses):
Method | |||||
---|---|---|---|---|---|
exitFullscreen() | 15.0 (webkit) | 11.0 (ms) | 9.0 (moz) | 5.1 (webkit) | 12.10 (webkit) |
Syntax
HTMLElementObject.exitFullscreen()
Parameters
None |
Technical Details
Return Value: | No return value |
---|
More Examples
You can use CSS to style the page when it is in fullscreen mode:
Example
/* Chrome, Safari and Opera syntax */
:-webkit-full-screen {
background-color: yellow;
}
/* Firefox syntax */
:-moz-full-screen {
background-color: yellow;
}
/* IE/Edge syntax */
:-ms-fullscreen {
background-color: yellow;
}
/* Standard syntax */
:fullscreen {
background-color: yellow;
}
Try it Yourself »
❮ Element Object