Checking if browser is in fullscreen
JavascriptJqueryJavascript Problem Overview
> Possible Duplicate:
> Detecting if a browser is in full screen mode
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.
Javascript Solutions
Solution 1 - Javascript
This works for all new browsers :
if (!window.screenTop && !window.screenY) {
alert('Browser is in fullscreen');
}
Solution 2 - Javascript
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 {
}
Solution 3 - Javascript
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)
Solution 4 - Javascript
I've ended up with following solution:
function _fullscreenEnabled() {
// FF provides nice flag, maybe others will add support for this later on?
if(window['fullScreen'] !== undefined) {
return window.fullScreen;
}
// 5px height margin, just in case (needed by e.g. IE)
var heightMargin = 5;
if($.browser.webkit && /Apple Computer/.test(navigator.vendor)) {
// Safari in full screen mode shows the navigation bar,
// which is 40px
heightMargin = 42;
}
return screen.width == window.innerWidth &&
Math.abs(screen.height - window.innerHeight) < heightMargin;
}
Which works in every browser I care about (Chrome, FF, IE, Safari/Mac, Opera).
Update: It doesn't work on Opera/Mac, Opera on Mac while in full screen mode hides only the 'common' OSX menu, thus height differs only by few pixels which is too dangerous for me.
Solution 5 - Javascript
this works on major browsers (ie,ff,opera,chrome)
function isFullscreen(){
if($.browser.opera){
var fs=$('<div class="fullscreen"></div>');
$('body').append(fs);
var check=fs.css('display')=='block';
fs.remove();
return check;
}
var st=screen.top || screen.availTop || window.screenTop;
if(st!=window.screenY){
return false;
}
return window.fullScreen==true || screen.height-document.documentElement.clientHeight<=30;
}
css for opera:
.fullscreen { display: none; }
@media all and (view-mode: fullscreen){
.fullscreen { display: block; }
}
Solution 6 - Javascript
Simple enough: Find the browser viewport using $(window).width()
and $(window).height()
, and if they conform to a set of defined viewport sizes (600 x 480, 1280 x 800, etc.), then you can know that it is most likely fullscreen. Also you can set event handlers for like the fll
key and other possible shortcuts to define browser fullscreen.