为什么window.onload = launchFullscreen(document.documentElement);不行? [英] Why window.onload = launchFullscreen(document.documentElement); not work?

查看:523
本文介绍了为什么window.onload = launchFullscreen(document.documentElement);不行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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();
    }
}


推荐答案

规范


如果满足以下任一条件,则排队任务以激发名为fullscreenerror的事件,并将其bubbles属性设置为true,然后在上下文对象的节点文档上终止这些步骤

If any of the following conditions are true, queue a task to fire an event named fullscreenerror with its bubbles attribute set to true on the context object's node document, and then terminate these steps

...

此算法不允许显示弹出窗口。

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);不行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆