首页 > 其他分享 >Failed to execute ‘requestFullscreen‘ on ‘Element‘

Failed to execute ‘requestFullscreen‘ on ‘Element‘

时间:2024-02-18 17:23:44浏览次数:29  
标签:execute else Failed requestFullscreen element 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()
            }
        }
    }

 



标签:execute,else,Failed,requestFullscreen,element,Element
From: https://www.cnblogs.com/shanhubei/p/18019616

相关文章