The browser does not allow listening to Esc by default
Chrome does not trigger a keystroke event when exiting full-screen mode. You need to define an event listener to listen for fullScreenChange events (fullscreen mode changes), like this (this thing is not well standardized, so you need to listen for events triggered by different browsers)
if (document.addEventListener) {
document.addEventListener('webkitfullscreenchange', exitHandler, false);
document.addEventListener('mozfullscreenchange', exitHandler, false);
document.addEventListener('fullscreenchange', exitHandler, false);
document.addEventListener('MSFullscreenChange', exitHandler, false);
}
Copy the code
Then, when the browser fires this event, it will call your custom exitHandler function, and you can do this when the user exits full-screen mode by doing the following:
function exitHandler() {
if (!document.webkitIsFullScreen && !document.mozFullScreen && !document.msFullscreenElement) {
... do something here
}
}
Copy the code