简体   繁体   English

Web 页面全屏打开,无需用户交互

[英]Web page open in full screen without user interaction

Is it possible to have a web page enter full screen without user interaction like this?是否有可能让 web 页面在没有像这样的用户交互的情况下进入全屏模式?

<body onload="openFullscreen()"></body>

Thanks in advance.提前致谢。

That is not possible.这是不可能的。

I ran the following snippet in my browser console:我在浏览器控制台中运行了以下代码段:

var e = document.getElementById('answers');
(e.webkitRequestFullScreen || e.mozRequestFullScreen).apply(e);

Chrome told me:铬告诉我:

Failed to execute 'requestFullScreen' on 'Element': API can only be initiated by a user gesture.无法在“元素”上执行“requestFullScreen”:API 只能由用户手势启动。

Firefox told me: Firefox 告诉我:

Request for full-screen was denied because Element.mozRequestFullScreen() was not called from inside a short running user-generated event handler.全屏请求被拒绝,因为 Element.mozRequestFullScreen() 未从短时间运行的用户生成的事件处理程序内部调用。

That is a restriction put in place to prevent abuse, similar to that on window.open (see this or this question for example).这是为防止滥用而设置的限制,类似于window.open上的限制(例如,请参阅此问题或此问题)。

You might be able to achieve this, but this will vary based upon your operating system.您可能能够实现这一点,但这会因您的操作系统而异。

This might work:这可能有效:

$(document).ready(function () {
    $('html').click(function () {
        if (screenfull.isFullscreen !== true) {
            screenfull.toggle();
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM