how exit browser's F11 fullscreen with javascript

为君一笑 提交于 2020-01-05 03:37:19

问题


Is there a way to exit the fullscreen that was created with hitting 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);
      },
    },

when in fullscreen mode using F11:
Fullscreen.element() is undefined and Fullscreen.exit() has no effect.

tried in latest version of Firefox and chrome.

Please, I will be tankful if you limit the comment/answer to related and constructive answers. Your personal opinion is not required nor is requested.

Please don't post links to JS Fullscreen solutions, I am already able to to that, see the code.

来源:https://stackoverflow.com/questions/44129672/how-exit-browsers-f11-fullscreen-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!