Javascript request fullscreen is unreliable
<p>I'm trying to use the JavaScript FullScreen API, using workarounds for current non-standard implementations from here:</p>

<p><a href="https://developer.mozilla.org/en/DOM/Using_full-screen_mode#AutoCompatibilityTable">https://developer.mozilla.org/en/DOM/Using_full-screen_mode#AutoCompatibilityTable</a></p>

<p>Sadly, it behaves very erratically. I only care about Chrome (using v17), but since I was having problems I did some tests in Firefox 10 for comparison, results are similar. </p>

<p>The code below attempts to set the browser to fullscreen, sometimes it works, sometimes not.  It ALWAYS calls the alert to indicate it is requesting fullscreen.  Here's what I've found:</p>

<ul>
<li>It USUALLY sets fullscreen.  It can get to a state where this stops working, but the alert still happens, i.e. it is still requesting FullScreen, but it doesn't work.</li>
<li>It can work if called from a keypress handler (document.onkeypress), but not when called on page loading (window.onload).</li>
</ul>

<p>My code is as follows:</p>

<pre><code>function DoFullScreen() {

    var isInFullScreen = (document.fullScreenElement &amp;&amp; document.fullScreenElement !==     null) ||    // alternative standard method  
            (document.mozFullScreen || document.webkitIsFullScreen);

    var docElm = document.documentElement;
    if (!isInFullScreen) {

        if (docElm.requestFullscreen) {
            docElm.requestFullscreen();
        }
        else if (docElm.mozRequestFullScreen) {
            docElm.mozRequestFullScreen();
            alert("Mozilla entering fullscreen!");
        }
        else if (docElm.webkitRequestFullScreen) {
            docElm.webkitRequestFullScreen();
            alert("Webkit entering fullscreen!");
        }
    }
}
</code></pre>
