有一个pad端需求,要求进到项目之后在浏览器中将整个项目全屏,
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() } } }标签:前端,js,else,requestFullscreen,element,兼容,全屏 From: https://www.cnblogs.com/HePandeFeng/p/18358166
实在main.js中写的script标签中实现的
会报错,Failed to execute ‘requestFullscreen’ on ‘Element’: API can only be initiated by a user gesture.
原因在于需要用户点击按钮触发事件,不允许onload触发,会用安全性问题。