Reputation: 886
What's a reliable, cross browser method of checking whether the window is in full screen mode in javascript?
To clarify, I am asking how to check whether we're currently in full screen or not and not whether the fullscreen API is enabled.
The answers in the question linked did not solve the problem. However, the accepted answer here did.
Upvotes: 0
Views: 1245
Reputation: 318182
For browsers that actually support the Fullscreen API, one can check the fullscreenElement
property to see if the browser is currently in fullscreen-mode.
If the window is not in fullscreen, the property is null
.
As it's still prefixed in some browser, all variations should be checked for support in all browsers supporting the Fullscreen API
if (document.fullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement ||
document.msFullscreenElement ) {
// in fullscreen
}
Upvotes: 1
Reputation: 1215
This works for all new browsers :
if (!window.screenTop && !window.screenY) {
alert('Browser is in fullscreen'); }
Upvotes: 0