浏览器无法自启动全屏模式
报错信息: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()
}
}
}