I'm working with Chrome and I want a simple task. Exiting full screen using code, not F11
key press.
Here are some documentations about how to implement it:
- https://www.w3schools.com/jsref/met_element_exitfullscreen.asp
- https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API
None of the above methods work. And also lots of non-working answers on Stack Overflow. Please help, I really need to solve this.
Here is my code:
const button = document.getElementById('exitId');
button.addEventListener("click", function(){
// JavaScript Code To Exit Fullscreen Goes Here
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();
}
});
<button id="exitId">Exit Fullscreen</button>
document.webkitExitFullscreen();