I'm trying to detect if the current document is fullscreen or not using:
document.addEventListener('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(e) {
if ((document.fullScreenElement && document.fullScreenElement !== null) ||
(!document.mozFullScreenElement && !document.webkitFullScreenElement)) {
console.log('fullscreen');
} else {
console.log('not fullscreen');
}
}, false);
But the event NEVER gets fired no matter I do to enter or exit fullscreen.
Any ideas?
Switching to fullscreen mode is done by calling Element. requestFullscreen() on the <video> element. If fullscreen mode is already active ( fullscreenElement is not null ), we call exitFullscreen() on the document to shut off fullscreen mode.
Basics of the Fullscreen API The word “request” in requestFullscreen is due to the fact that browsers don't have permissions (by default) to activate fullscreen mode. Using the above function, to activate fullscreen, simply pass the document HTMLElement!
Use a keyboard shortcut to switch between full screen and normal display modes. When screen space is at a premium and you only need SecureCRT on your screen, press ALT+ENTER (Windows) or COMMAND+ENTER (Mac). The application will expand to full screen, hiding the menu bar, tool bar, and title bar.
Full-screen can be activated for the whole browser window by pressing the F11 key. It can be exited by pressing the Esc button. It is also possible to make a specific element in the page to enter and exit full-screen mode programmatically using Javascript Fullscreen API.
A convenient library-free solution:
["fullscreenchange", "webkitfullscreenchange", "mozfullscreenchange", "msfullscreenchange"].forEach(
eventType => document.addEventListener(eventType, yourCheckFunction, false)
);
or alternatively:
["", "webkit", "moz", "ms"].forEach(
prefix => document.addEventListener(prefix+"fullscreenchange", yourCheckFunction, false)
);
Are you sure you didn't mean to use the jQuery bind
?
The document.addEventListener
does not support multiple events as far as I know.
Use this example (based on this question on SO) if you like to use jQuery:
$(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange', function(e)
{
//do something;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With