美文网首页技术码头
全屏,退出全屏

全屏,退出全屏

作者: 石菖蒲_xl | 来源:发表于2018-11-30 10:24 被阅读1次

    笔记

    注意:不能自动调用,必须手动触发

     requestFullScreen() {
        let el = document.documentElement;
        let rfs = el.requestFullScreen || el.webkitRequestFullScreen ||
          el.mozRequestFullScreen || el.msRequestFullScreen;
        if (rfs) { //typeof rfs != "undefined" && rfs
          rfs.call(el);
        } else if (typeof window.ActiveXObject != 'undefined') {
          //for IE,这里其实就是模拟了按下键盘的F11,使浏览器全屏
          let wscript = new ActiveXObject('WScript.Shell');
          if (wscript != null) {
            wscript.SendKeys('{F11}');
          }
        }
    
      }
    
    cancelFullScreen() {
        let el = document;
        let cfs = el.cancelFullScreen || el.webkitCancelFullScreen ||
          el.mozCancelFullScreen || el.exitFullScreen;
        if (cfs) { //typeof cfs != "undefined" && cfs
          cfs.call(el);
        } else if (typeof window.ActiveXObject != 'undefined') {
          //for IE,这里和fullScreen相同,模拟按下F11键退出全屏
          let wscript = new ActiveXObject('WScript.Shell');
          if (wscript != null) {
            wscript.SendKeys('{F11}');
          }
        }
      }
    

    相关文章

      网友评论

        本文标题:全屏,退出全屏

        本文链接:https://www.haomeiwen.com/subject/tqmccqtx.html