Why does document.body.requestFullscreen() work on the first invocation only?

ぐ巨炮叔叔 提交于 2020-04-30 06:37:21

问题


I have the following method which works on the 1st call, however if I hit the Esc key and then try my FullScreen button nothing happens. Debugging the code shows the else is not executing so document.body.requestFullScreen() is being called again but it has no effect??

What did I miss?

    /**
     * Full Screen Mode
     + works on Windows7 Chrome v80 and Android Chrome.
     - 20180415
     - 20200417 Moved from ChannelsTitleComp
     */
    FullScreenToggle() {
        // document.body.requestFullscreen() works on Windows Chrome and Android Chrome.
        // https://stackoverflow.com/questions/53048372/how-to-programmatically-switch-display-from-standalone-to-fullscreen-in-pwa
        if (document.body.requestFullscreen) {
            document.body.requestFullscreen()
        }
        else {
            Log.Write(this, "requestFullscreen", document.body.requestFullscreen)
            document.exitFullscreen()
        }

did not incorporate something like this for a toggle YET

 // https://developers.google.com/web/fundamentals/native-hardware/fullscreen/
            if (document.fullscreenElement)
                document.exitFullscreen()

Thank you for your insights.

20200418 16:42 Update

A reply from Oscar requested to print the value of requestFullscreen the second time thru. I did and t seems to be the same according to the following console output.

Here is the code I used

来源:https://stackoverflow.com/questions/61283183/why-does-document-body-requestfullscreen-work-on-the-first-invocation-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!