相关文章推荐
一身肌肉的茶叶  ·  excel WSD - CSDN文库·  4 月前    · 
有腹肌的伤痕  ·  sql ...·  1 年前    · 
眉毛粗的跑步鞋  ·  Perl ...·  1 年前    · 

js判断浏览器是否全屏

点击事件

      <span class="iconfont icon-quanping1" @click="fullscreenchange"></span>
    fullscreenchange() {
    // fullScreen 被弃用
    // const isFullScreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement
    // 最新写法
          const isFullScreen = document.fullscreenElement
      if (isFullScreen) {
        console.log('退出全屏')
        if (document.exitFullscreen) {
          document.exitFullscreen()
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen()
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen()
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen()
      } else {
        var fullscreen = this.$refs.fullscreen   // 需要全屏的元素
        console.log('进入全屏')
        if (fullscreen.requestFullscreen) {
          fullscreen.requestFullscreen()
        } else if (fullscreen.mozRequestFullScreen) {
          fullscreen.mozRequestFullScreen()
        } else if (fullscreen.webkitRequestFullscreen) {
          fullscreen.webkitRequestFullscreen()
        } else if (fullscreen.msRequestFullscreen) {
          fullscreen.msRequestFullscreen()

参考链接:developer.mozilla.org/zh-CN/docs/…

  •