Detect fullscreen mode

前端 未结 16 2128
谎友^
谎友^ 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:27

    Proposed solution using:

    return window.innerHeight == screen.height && window.innerWidth == screen.width;
    

    works fine, but only in case you're not zooming your browser.

    To handle cases with zoomed screen use following:

    let zoom = window.outerWidth / window.innerWidth;
    return (window.innerHeight * zoom) == screen.height && (window.innerWidth * zoom) == screen.width;
    

    to detemine zoom and then multiply window.innerHeight and window.innerWidth.

提交回复
热议问题