tinfanide Posted September 30, 2011 Share Posted September 30, 2011 I want to detect if Firefox is in fullscreen mode.Is there a way to do so in JS? Link to comment Share on other sites More sharing options...
ShadowMage Posted September 30, 2011 Share Posted September 30, 2011 This is just a guess, but I'm going to say no. That's related to browser behavior which cannot be affected. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 30, 2011 Share Posted September 30, 2011 You may be able to compare the total screen size with the document size and check how close they are. Link to comment Share on other sites More sharing options...
tinfanide Posted October 1, 2011 Author Share Posted October 1, 2011 How can it be done?Should I use screen.availWidth to detect the total screen size? Link to comment Share on other sites More sharing options...
Ingolme Posted October 1, 2011 Share Posted October 1, 2011 It's in the W3Schools reference: http://w3schools.com/jsref/obj_screen.asp availWidth contains the width of the screen excluding the task bar, availHeight contains the height of the screen excluding the task bar. You can test availWidth and availHeight compared to width and height. If they're both equal, then it's probably in full screen mode. Link to comment Share on other sites More sharing options...
tinfanide Posted October 1, 2011 Author Share Posted October 1, 2011 I try this: document.write(screen.height);document.write(screen availHeight); But when I press F11 in FF, it turns to its full screen mode but the screen availHeight is still not equal to screen height.Then how can I compare them to detect if users open FF in fullscreen mode? This is my script to detect the full screen mode: function fullscreenConfig(){ if(navigator.userAgent.indexOf("Firefox")!=-1){ var fullscreenReminder = document.createElement("div"); fullscreenReminder.style.color = "white"; fullscreenReminder.innerHTML = "Press F11 on the keyboard to enjoy a fullscreen view of the gallery"; document.body.appendChild(fullscreenReminder); if(parseInt(screen.availWidth) == parseInt(screen.width) && parseInt(screen.availHeight) == parseInt(screen.height))(alert("Fullscreen Mode")) } } Link to comment Share on other sites More sharing options...
Ingolme Posted October 1, 2011 Share Posted October 1, 2011 The numbers don't update automatically. When you change to full screen, the values printed there are still the old ones. Try running a function that prints the value when a button is clicked. Remember that some computers have the task bar on the bottom or top, while others have it on the sides, so you have to test both. Javascript:function testSize() { document.getElementById("output").innerHTML = "Full height: " + screen.height + "\nAvailable height: " + screen.availHeight; document.getElementById("output").innerHTML += "Full width: " + screen.width+ "\nAvailable width: " + screen.availWidth;} HTML:<button type="button" onclick="testSize()">Click</button><div id="output"></div> Link to comment Share on other sites More sharing options...
tinfanide Posted October 1, 2011 Author Share Posted October 1, 2011 Well... I've tested the script. My screen resolution is: 1920*1080. When I click in non-fullscreen FF, the availHeight is 1040;When I run FF in fullscreen, I refresh the page and click the button again, the availHeight is still 1040. So I think it's impossible to detect if FF users switch to the fullscreen mode. Link to comment Share on other sites More sharing options...
Ingolme Posted October 1, 2011 Share Posted October 1, 2011 It seems that even when in full screen, the task bar doesn't actually disappear, so using the availWidth property won't help. I just tested, using window.outerWidth and window.outerHeight you can detect the size. if(window.outerWidth == screen.width && window.outerHeight == screen.height) { // The browser is in full screen mode} outerWidth and outerHeight are exclusive to Firefox Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.