Fullscreen API not working if triggered with F11

后端 未结 3 780
半阙折子戏
半阙折子戏 2021-02-19 14:27

I implemented a fullscreen toggling feature for my application and it is actually working fine, tested on newest Chrome, Firefox, IE and Opera. I have one method for activating

3条回答
  •  猫巷女王i
    2021-02-19 14:45

    You can use the display-mode: fullscreen media query which properly captures both Fullscreen API changes and F11.

    CSS version:

    #fullscreen::before {
        content: 'not ';
    }
    
    @media (display-mode: fullscreen) {
        #fullscreen::before {
            content: none;
        }
    }
    fullscreen

    JavaScript version:

    const el = document.getElementById('fullscreen')
    
    const query = matchMedia('(display-mode: fullscreen)')
    const handler = e => {
        el.innerHTML = (e.matches ? '' : 'not ') + 'fullscreen'
    }
    
    handler(query)
    query.addListener(handler)

提交回复
热议问题