Detecting if a browser is in full screen mode

后端 未结 17 1868
误落风尘
误落风尘 2020-11-27 06:10

Is there any way of reliably detecting if a browser is running in full screen mode? I\'m pretty sure there isn\'t any browser API I can query, but has anyone worked it out b

17条回答
  •  再見小時候
    2020-11-27 06:47

    You can 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");              
              }
          });
    

提交回复
热议问题