JS调用命令实现F11全屏

Posted 王大白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS调用命令实现F11全屏相关的知识,希望对你有一定的参考价值。

<body onload =\'autoSetFull()\'>
  <button id=\'btn\'>全屏按钮</button>  
  <div id="content" style="background:yellow;width:500px;height:500px;">sljfsdlfj  
      <div id="quite" class="btn">退出全屏</div>  
  </div> 
<body> 
<script type="text/javascript">
  function fullScreen(el) {  
      var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen,  
          wscript;  
      if(typeof rfs != "undefined" && rfs) {  
          rfs.call(el);  
          return;  
      }  
      if(typeof window.ActiveXObject != "undefined") {  
          wscript = new ActiveXObject("WScript.Shell");  
          if(wscript) {  
              wscript.SendKeys("{F11}");  
          }  
      }  
  }  
  function exitFullScreen(el) {  
      var el= document,  
          cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen,  
          wscript;  
     
      if (typeof cfs != "undefined" && cfs) {  
        cfs.call(el);  
        return;  
      }  
     
      if (typeof window.ActiveXObject != "undefined") {  
          wscript = new ActiveXObject("WScript.Shell");  
          if (wscript != null) {  
              wscript.SendKeys("{F11}");  
          }  
    }  
  }  
  var btn = document.getElementById(\'btn\');  
  var content = document.getElementById(\'content\');  
  btn.onclick = function(){  
      fullScreen(content);  
  }  
  var quite = document.getElementById(\'quite\');  
  quite.onclick = function(){  
      exitFullScreen();  
  }  
</script>

PS:这种方法只能通过用户来触发,尝试页面加载后自动执行会提示错误。

 

以上是关于JS调用命令实现F11全屏的主要内容,如果未能解决你的问题,请参考以下文章

js 实现全屏预览(F11功能)--转

让用户端JS触发F11全屏

浏览器全屏之requestFullScreen全屏与F11全屏

vue+iframe实现点击F11全屏效果

用js怎样实现打开网页时就全屏显示,要支持chrome,Firefox,IE等主流浏览器,求大神帮忙啊!

HBuilderX编辑器F11退出全屏无效的解决办法 - 切换免打扰模式