Detecting if a browser is in full screen mode

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

    While searching high & low I have found only half-solutions. So it's better to post here a modern, working approach to this issue:

    var isAtMaxWidth = (screen.availWidth - window.innerWidth) === 0;
    var isAtMaxHeight = (screen.availHeight - window.outerHeight <= 1);
    if (!isAtMaxWidth || !isAtMaxHeight) {
           alert("Browser NOT maximized!");
    }
    

    Tested and working properly in Chrome, Firefox, Edge and Opera* (*with Sidebar unpinned) as of 10.11.2019. Testing environment (only desktop):

    CHROME - Ver. 78.0.3904.97 (64-bit)
    FIREFOX - Ver. 70.0.1 (64-bit)
    EDGE - Ver. 44.18362.449.0 (64-bit)
    OPERA - Ver. 64.0.3417.92 (64-bit)
    OS - WIN10 build 18362.449 (64-bit)
    

    Resources:

    • https://developer.mozilla.org/en-US/docs/Web/API/Screen/availWidth
    • https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth
    • https://developer.mozilla.org/en-US/docs/Web/API/Screen/availHeight
    • https://developer.mozilla.org/en-US/docs/Web/API/Window/outerHeight

提交回复
热议问题