JavaScript Button to Toggle Fullscreen (F11)

<a href="#full" onclick="toggleFullScreen()">Fullscreen</a>

<script>
        function toggleFullScreen() {
          var doc = window.document;
          var docEl = doc.documentElement;

          var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
          var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;

          if(!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
            requestFullScreen.call(docEl);
          }
          else {
            cancelFullScreen.call(doc);
          }
        }
    </script>
+1

Leave a Reply