PDA

View Full Version : Making current window full-screen using JavaScript



codeexploiter
09-07-2007, 05:11 AM
Hi,

I wonder is there any method in JavaScript using which we can make the current window full-screen (the effect we get when we press F11 key in browser window). I am looking for a cross-browser solution (I know there is a activex based method using which it can be achieved for IE but I think the method seems to be bit offensive as far as Firewalls/Anti-viruses are concerned)

regards

Codex

jscheuer1
09-07-2007, 09:02 AM
In modern browsers, nothing straightforward, really nothing at all that is fully cross browser. You can use the:


window.resizeTo(width, height);

method coupled with the:


window.moveTo(left, top);

method, using screen.availWidth and screen.availHeight as the width and height and 0 as the left and top. But many browsers can be set to not allow that. It is a user configuration. Some come with it already disallowed, the user would have to turn it on. Those that do allow it will 'do the math' slightly differently from one another, so it won't always be exactly like hitting F11 would be. Browsers will still allow this window to be restored, but some will think that it already is restored, so nothing will happen. This pisses off a lot of users when it happens to them - not being able to restore down their window in the accustomed manner, even after closing the browser session.

Another approach is to have your page launch a new window of itself with the desired size. This is even trickier what with pop up blockers.

You might be able to combine the two methods with tests to see if either is allowed/accomplished to see which to use. Even if everything works out, there will still be some chrome.

However, it would probably be best to simply have a script that determines whether or not the window.innerWidth x window.innerHeight (document.documentElement.clientWidth and Height in IE) is already at or very near to the size of the user's screen.width by their screen.height, and if not, pop up an alert or have a large message appear on the page that advises them to ht F11.

This has the advantage of being slightly less annoying than trying to take over the user's window by brute force.