1
I was trying to find some way to detect if the page entered "full screen" mode, for example tight F11.
I saw there was an event fullscreenchange Event, but it appears not to work when pressing F11. It only works if the JS itself triggers the fullscreen (using the Fullscreen API.
The code I used that doesn’t work was:
document.addEventListener('fullscreenchange', function(e) {
console.log("fullscreen", e);
});
When F11 grip was expected to show the message, but it does not seem. It only seems to call via document.documentElement.requestFullscreen();
.
EDIT: THE matchMedia
ALSO DOESN’T WORK:
window.matchMedia('(display-mode: fullscreen)').addListener(function(e) {
console.log(e);
})
window.matchMedia('(display-mode: fullscreen)').addEventListener("change", function(e) {
console.log(e);
})
Is there any other event or way of knowing when the window enters (or exits) full-screen mode?
You can use the event
keydown
to detect the key F11 (keycode 122) you just won’t know if it came full screen or came out.– gleisin-dev