Detecting if a browser is in full screen mode

后端 未结 17 1791
误落风尘
误落风尘 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:30

    This works for all new browsers :

    if (!window.screenTop && !window.screenY) { 
       alert('Browser is in fullscreen');
    }
    
    0 讨论(0)
  • 2020-11-27 06:31

    Right. Totally late on this one...

    As of 25th Nov, 2014 (Time of writing), it is possible for elements to request fullscreen access, and subsequently control entering/exiting fullscreen mode.

    MDN Explanation here: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode

    Straightforward explanation by David Walsh: http://davidwalsh.name/fullscreen

    0 讨论(0)
  • 2020-11-27 06:32

    Chrome 15, Firefox 10, and Safari 5.1 now provide APIs to programmatically trigger fullscreen mode. Fullscreen mode triggered this way provides events to detect fullscreen changes and CSS pseudo-classes for styling fullscreen elements.

    See this hacks.mozilla.org blog post for details.

    0 讨论(0)
  • 2020-11-27 06:32

    What about determining the distance between the viewport width and the resolution width and likewise for height. If it is a small amount of pixels (especially for height) it may be at fullscreen.

    However, this will never be reliable.

    0 讨论(0)
  • 2020-11-27 06:37

    Opera treats full screen as a different CSS media type. They call it Opera Show, and you can control it yourself easily:

    @media projection {
      /* these rules only apply in full screen mode */
    }
    

    Combined with Opera@USB, I've personally found it extremely handy.

    0 讨论(0)
  • 2020-11-27 06:38

    To detect whether browser is in fullscreen mode:

    document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement
    

    according to caniuse you should be fine for majority of browsers.

    0 讨论(0)
提交回复
热议问题