问题描述
我使用 launchFullscreen()
函数获取页面全屏。它完美的使用按钮 onClick
。但它不适用于 window.onload
。有没有办法从onload调用该函数。
I use launchFullscreen()
function for get page full screen. It's work perfect with button onClick
.But It doesn't work with window.onload
. Are there are any way to call that function from onload.
window.onload = launchFullscreen(document.documentElement);
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();
}
}
推荐答案
:
...
此算法不允许显示弹出窗口。
This algorithm is not allowed to show a pop-up.
全屏模式只能在允许显示弹出窗口时触发。
Full screen mode may only be triggered at times when it is allowed to show a popup.
您可能只会响应用户事件显示弹出式窗口。
You may only show a popup in response to a user event.
点击是用户事件。
文档加载不是。
这是没有办法的。
另外,正如Theo's指出的那样答案是,你立即调用 launchFullscreen
并试图使用它的返回值(不是函数)作为加载事件处理程序。在这种情况下,它没有区别。
An an aside, as pointed out in Theo's answer, you are calling launchFullscreen
immediately and trying to use its return value (not a function) as the load event handler. In this case, it makes no difference though.
这篇关于为什么window.onload = launchFullscreen(document.documentElement);不行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!