启动全屏functionlaunchFullscreen(element){if(element.requestFullscreen){element.requestFullscreen();}elseif(element.mozRequestFullScreen){element.mozRequestFullScreen();}elseif(element.webkitRequestFullscreen){element.webkitRequestFullscreen();}elseif(element.msRequestFullscreen){element.msRequestFullscreen();}}现在这段代码只能点击按钮才能全屏,有没有什么方法自动全屏浏览器的请给出代码实现谢谢
2 回答
MMTTMM
TA贡献1869条经验 获得超4个赞
我试着改写成立即执行的函数表达式:(functionlaunchFullscreen(element){if(element.requestFullscreen){element.requestFullscreen();}elseif(element.mozRequestFullScreen){element.mozRequestFullScreen();}elseif(element.webkitRequestFullscreen){element.webkitRequestFullscreen();}elseif(element.msRequestFullscreen){element.msRequestFullscreen();}})(document.documentElement);但是chrome提示:Failedtoexecute'requestFullScreen'on'Element':APIcanonlybeinitiatedbyausergesture.貌似意设定:这种api操作只能有人来出发。。。api给的例子也是由一个条件来出发这个html5的全屏函数:element.requestFullScreen()Makesanindividualelementfull-screen,e.g.document.getElementById(“myvideo”).requestFullScreen().
添加回答
举报
0/150
提交
取消