美文网首页
js 实现浏览器全屏、退出和监控

js 实现浏览器全屏、退出和监控

作者: 晨阁先生 | 来源:发表于2020-07-16 10:55 被阅读0次

    兼容火狐、谷歌、IE11及以上浏览器

    //全屏显示
    
    launchFullscreen(element) {
    
      if(element.requestFullscreen) {
    
        element.requestFullscreen();
    
      } else if(element.mozRequestFullScreen) {
    
        element.mozRequestFullScreen();
    
      } else if(element.webkitRequestFullscreen) {
    
        element.webkitRequestFullscreen();
    
      } else if(element.msRequestFullscreen) {
    
        element.msRequestFullscreen();
    
      }
    
    },
    
    // 退出全屏
    
    exitFullscreen () {
    
      if(document.exitFullscreen) {
    
        document.exitFullscreen();
    
      } else if(document.mozCancelFullScreen) {
    
        document.mozCancelFullScreen();
    
      } else if(document.webkitExitFullscreen) {
    
        document.webkitExitFullscreen();
    
      }
    
    },
    
    //监听全屏状态,全屏返回dom,否则返回false
    
    watchFullScreen(){
    
      document.addEventListener("fullscreenchange", function () { 
    
              var isFull = document.fullscreenElement    ||
    
                      document.msFullscreenElement  ||
    
                      document.mozFullScreenElement ||
    
                      document.webkitFullscreenElement || false;
    
        }, false); 
    
        document.addEventListener("mozfullscreenchange", function () {
    
             var isFull = document.fullscreenElement    ||
    
                      document.msFullscreenElement  ||
    
                      document.mozFullScreenElement ||
    
                      document.webkitFullscreenElement || false;
    
        }, false); 
    
        document.addEventListener("webkitfullscreenchange", function () { 
    
               var isFull = document.fullscreenElement    ||
    
                      document.msFullscreenElement  ||
    
                      document.mozFullScreenElement ||
    
                      document.webkitFullscreenElement || false;
    
        }, false); 
    
        document.addEventListener("msfullscreenchange", function () { 
    
              var isFull = document.fullscreenElement    ||
    
                      document.msFullscreenElement  ||
    
                      document.mozFullScreenElement ||
    
                      document.webkitFullscreenElement || false;
    
        }, false);
    
    },
    

    相关文章

      网友评论

          本文标题:js 实现浏览器全屏、退出和监控

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