Detect fullscreen mode

前端 未结 16 2158
谎友^
谎友^ 2020-11-28 08:01

Modern desktop version of IE 10 is always fullscreen.

There is a living specification for :fullscreen pseudo-class on W3

But when I tried to det

16条回答
  •  感动是毒
    2020-11-28 08:35

    Use fullscreenchange event to detect a fullscreen change event, or if you don't want to handle vendor prefixes than you can also listen to the resize event (the window resize event that also triggers when fullscreen is entered or exited) and then check if document.fullscreenElement is not null to determine if fullscreen mode is on. You'll need to vendor prefix fullscreenElement accordingly. I would use something like this:

    var fullscreenElement = document.fullscreenElement || document.mozFullScreenElement ||
    document.webkitFullscreenElement || document.msFullscreenElement;
    

    https://msdn.microsoft.com/en-us/library/dn312066(v=vs.85).aspx has a good example for this which I quote below:

    document.addEventListener("fullscreenChange", function () {
              if (fullscreenElement != null) {
                  console.info("Went full screen");
              } else {
                  console.info("Exited full screen");              
              }
          });
    

提交回复
热议问题