我试着改写成立即执行的函数表达式:
(function launchFullscreen(element) {
if(element.requestFullscreen) {
element.requestFullscreen();
} else if(element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if(element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if(element.msRequestFullscreen) {
element.msRequestFullscreen();
}
})(document.documentElement);
但是chrome提示:
Failed to execute 'requestFullScreen' on 'Element': API can only be initiated by a user gesture.
貌似意设定:这种api操作只能有人来出发。。。
api给的例子也是由一个条件来出发这个html5的全屏函数:
element.requestFullScreen()
Makes an individual element full-screen, e.g. document.getElementById(“myvideo”).requestFullScreen().