หน้าเว็บ

วันจันทร์ที่ 4 มีนาคม พ.ศ. 2556

การทำ browser full screen javascript

before, thank you very much for this link : http://stackoverflow.com/questions/7495373/how-to-make-browser-full-screen-using-f11-key-event-through-javascript 



utilities.js
var FullScreen = {

    toggle : function(element) {
        element = element || document.body;

        var full = (document.fullScreenElement && document.fullScreenElement !== null) 
                || (document.mozFullScreen || document.webkitIsFullScreen);
        var requestScreen;

        if (full) {
            element = document;
            requestScreen = element.cancelFullScreen
                    || element.webkitCancelFullScreen
                    || element.mozCancelFullScreen
                    || element.exitFullscreen;
        } else {
            requestScreen = element.requestFullScreen
                    || element.webkitRequestFullScreen
                    || element.mozRequestFullScreen
                    || element.msRequestFullScreen;
        }

        if (requestScreen) { // Native full screen.
            requestScreen.call(element);
        } else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
            var wscript = new ActiveXObject("WScript.Shell");
            if (wscript !== null) {
                wscript.SendKeys("{F11}");
            }
        }
    }
}
Example to use
<html>
   <head>
      <style type="text/css">
          body{
              width : 100%;
              height : 100%;
              padding : 0px;
              margin : 0px;
         }
     </style>
     <script type="text/javascript" src="utilities.js"></script>
   </head>
   <body>
      <button onclick="FullScreen.toggle(document.body);">Toggle Full Screen</button>
   </body>
</html>

ไม่มีความคิดเห็น:

แสดงความคิดเห็น