Failed to execute ‘requestFullscreen‘ on ‘Element‘

来源:http://www.shanhubei.com/archives/13628.html

浏览器无法自启动全屏模式
报错信息:Failed to execute ‘requestFullscreen’ on ‘Element’: API can only be initiated by a user gesture.
翻译:无法在element上执行requestFullscreen方法,这个API只有用户主动行为才可以触发。

    window.onload = () => {
        let element = document.documentElement
        if (element.requestFullscreen) {
                element.requestFullscreen()
            } else if (element.msRequestFullscreen) { // 兼容ie
                element.msRequestFullscreen()
            } else if (element.mozRequestFullScreen) { // 兼容火狐
                element.mozRequestFullScreen()
            } else if (element.webkitRequestFullscreen) { // 兼容chrome和safari
                element.webkitRequestFullscreen()
            }
        }
    }

 



posted @ 2024-02-18 17:12  珊瑚贝博客  阅读(812)  评论(0编辑  收藏  举报