如何使用javascript退出浏览器的F11全屏

时间:2017-05-23 08:30:21

标签: javascript html fullscreen

有没有办法退出通过点击F11创建的全屏?

FullScreen: {
      _callback: null,
      enabled  : function () {
        return document.fullscreenEnabled ||
          document.webkitFullscreenEnabled ||
          document.mozFullScreenEnabled ||
          document.msFullscreenEnabled;
      },

      request: function (i) {
        if (i.requestFullscreen) {
          i.requestFullscreen();
        } else if (i.webkitRequestFullscreen) {
          i.webkitRequestFullscreen();
        } else if (i.mozRequestFullScreen) {
          i.mozRequestFullScreen();
        } else if (i.msRequestFullscreen) {
          i.msRequestFullscreen();
        }
      },

      element: function () {
        return document.fullscreenElement ||
          document.webkitFullscreenElement ||
          document.mozFullScreenElement ||
          document.msFullscreenElement;
      },

      exit: function () {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.webkitExitFullscreen) {
          document.webkitExitFullscreen();
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
      },

      onChange: function (fn) {
        if (document.fullscreenEnabled)
          document.addEventListener('fullscreenchange', fn);
        else if (document.webkitFullscreenEnabled)
          document.addEventListener('webkitfullscreenchange', fn);
        else if (document.mozFullScreenEnabled)
          document.addEventListener('mozfullscreenchange', fn);
        else if (document.msFullscreenEnabled)
          document.addEventListener('MSFullscreenChange', fn);
      },

      removeOnChange: function (fn) {
        if (document.fullscreenEnabled)
          document.removeEventListener('fullscreenchange', fn);
        else if (document.webkitFullscreenEnabled)
          document.removeEventListener('webkitfullscreenchange', fn);
        else if (document.mozFullScreenEnabled)
          document.removeEventListener('mozfullscreenchange', fn);
        else if (document.msFullscreenEnabled)
          document.removeEventListener('MSFullscreenChange', fn);
      },
    },

使用F11进入全屏模式时:
Fullscreen.element()undefinedFullscreen.exit()无效。

尝试使用最新版本的Firefox和chrome。

如果你限制对相关和建设性答案的评论/回答,我会很坦白。您的个人意见不是必需的,也不是必需的。

请不要发布JS Fullscreen解决方案的链接,我已经能够查看,请参阅代码。

0 个答案:

没有答案