views:

136

answers:

2

Is there a way to check if a browser is currently in fullscreen mode (after the user pressed f11)?

Something like:

if (window.fullscreen) {
  // it's fullscreen!
}
else {
  // not fs!
}

Thanks.

Steerpike's answer is pretty good, but my comment:

Thanks a lot, but this answer is not sufficient for FF. In Chrome I can set a small tolerance, but in FF the urlbar and tabs takes a while to disappear, which means after pressing f11, the detected window.innerWidth is still too small.

+6  A: 
if(window.innerWidth == screen.width && window.innerHeight == screen.height) {

} else {

}

(Warning: The browser chrome may muck with the height comparisons but the width checks should be pretty spot on)

Steerpike
I expect you'll want to have some margin of difference, since some browsers still have a couple of pixels at the top reserved for a bar that will slide down when you hover over it, which will throw off this check.
Kazar
Yeah, the check definitely needs some tolerance. Other than that: +1
Pekka
Don't forget that `innerWidth` and `innerHeight` are [not supported](http://www.quirksmode.org/dom/w3c_cssom.html#windowview) by IE.
CMS
Thanks a lot, but this answer is not sufficient for FF. In Chrome I can set a small tolerance, but in FF the urlbar and tabs takes a while to disappear, which means after pressing f11, the detected window.innerWidth is still too small.
Mark
You could still admit a bigger tolerance, as most of the browser have at least an address bar, you can guess that the height difference could be of n pixels.
Boris Guéry
OK, yes you're right... why did I think that... Sorry, way too late! A value of 63px worked for me.
Mark
A: 

In Firefox 3, window.fullScreen works (https://developer.mozilla.org/en/DOM/window.fullScreen).

So, you could potentially do something like this:

if((window.fullScreen) ||
   (window.innerWidth == screen.width && window.innerHeight == screen.height)) {

} else {

}
user4815162342