0

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.

Lucien
  • 776
  • 3
  • 12
  • 40
  • 1
    What is wrong with [Checking if browser is in fullscreen](http://stackoverflow.com/questions/2863351/checking-if-browser-is-in-fullscreen)? – t.niese Nov 29 '15 at 19:56
  • @t.niese, the `window.fullscreen` is `undefined`. I have also tried `document.fullscreen` and `myelement.fullscreen`. – Lucien Nov 29 '15 at 19:57
  • js varables are case sensitive, beside that it is not the only technique mentioned there. – t.niese Nov 29 '15 at 20:01
  • @t.niese, the answer that I was given here worked and isn't in the other question though. How should questions like this be handled? `.fullScreen` was failing too by the way. – Lucien Nov 29 '15 at 20:02

2 Answers2

1

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

}

DEMONSTRATION

adeneo
  • 312,895
  • 29
  • 395
  • 388
0

This works for all new browsers :

if (!window.screenTop && !window.screenY) {
    alert('Browser is in fullscreen'); }
Khairul Islam
  • 1,207
  • 1
  • 9
  • 20
  • This unfortunately did not work correctly. I am using the latest (or very close) version of Waterfox. – Lucien Nov 29 '15 at 20:01
  • It returns true if fullscreen is not enabled but the browser window is located at the upper left corner of the screen. (Windows 10, Chrome 65) – Metafr Jan 18 '18 at 09:55