title: Cross Browser fullscreen mode
body: <p>In my app, I want users to be able to press a button or F11 to go full screen. However the call to browser to go full screen should go through my custom function as there is additional code which recalculates some variables.</p>
  
  <p>The updated code &amp; link demonstrate that the browser ignores our wrapper function &amp; calls its own fullscreen function immediately with F11 press.</p>
  
  <p>David Walsh has an intro but I cannot seem to be able to pull it off our custom function bit. </p>
  
  <p>The demo works on Chrome but not on Firefox... </p>
  
  <p><a href="http://davidwalsh.name/fullscreen" rel="nofollow">David Walsh article on Full screen API</a></p>
  
  <pre><code>        document.addEventListener('keydown', keyInput, false);
          var fullscreen_flag = false;
  
          function keyInput(event) {
              event.preventDefault();
              console.log('user press key');
              var code = event.keyCode || event.which;
              if (code === 122) {  // F11 pressed                                               
                  requestFullScreen('key request');
              }
          }
  
          function requestFullScreen(text) {
  
              if (fullscreen_flag) {                   
                  exitFullscreen(text);                    
              }
  
              else {                   
                  triggerFullScreen(text);                    
              }
          }
  
          function triggerFullScreen(text){
              fullscreen_flag=true;
               //alert('Fullscreen Enabled!');
               console.log(text);
              var elementDom = document.getElementsByTagName('body')[0];
          elementDom.requestFullscreen = elementDom.requestFullscreen ||
          elementDom.mozRequestFullScreen || elementDom.webkitRequestFullscreen ||
          elementDom.msRequestFullscreen;
  
          elementDom.requestFullscreen();
          }
  
          function exitFullscreen(text) {
              console.log(text);
              fullscreen_flag = false;
               //alert('Exiting Fullsreen!');
              document.exitFullscreen = document.exitFullscreen || document.mozCancelFullScreen || document.webkitExitFullscreen || document.msExitFullscreen;
  
          document.exitFullscreen();
  
          }
  </code></pre>