javascript 全屏在单击时工作但在加载时不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14244397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:07:41  来源:igfitidea点击:

FullScreen works onclick but not onload

javascripthtml

提问by ispiro

I'm trying the code from hereto start fullscreen mode. It works if executed onclick, but not onload. (I've also discovered that setting an alertbefore it will disable it unless the alertis clicked immediately.) So perhaps the problem is that sometimes the browser isn't 'ready' for fullscreen.

我正在尝试使用此处的代码来启动全屏模式。如果执行onclick,它会起作用,但不会onload。(我还发现alert在它之前设置一个会禁用它,除非alert立即点击它。)所以也许问题是有时浏览器没有“准备好”全屏。

So what is the last event fired when a page is completely ready? Or is the solution different?

那么当页面完全准备好时,最后触发的事件是什么?还是解决方法不一样?

回答by Louis Ricci

Fullscreen requires user interaction to initiate. It's a security feature.

全屏需要用户交互才能启动。这是一个安全功能。

Imagine if some pop-up could force you into fullscreen mode, lock your mouse pointer, and start playing an advertisement without your permission.

想象一下,如果某个弹出窗口可以强制您进入全屏模式,锁定鼠标指针,并在未经您许可的情况下开始播放广告。

Having a 'enable full screen' link or button who's visibility is toggled in the document 'fullscreenchange' event handler seems like a practical approach.

在文档“fullscreenchange”事件处理程序中切换可见性的“启用全屏”链接或按钮似乎是一种实用的方法。

回答by H3llrais3R

well this might help Fullscreen script

那么这可能有助于全屏脚本

But I agree with LastCoder

但我同意LastCoder

Fullscreen requires user interaction to initiate. It's a security feature.

Imagine if some pop-up could force you into fullscreen mode, lock your mouse pointer, and start playing an advertisement without your permission.

全屏需要用户交互才能启动。这是一个安全功能。

想象一下,如果某个弹出窗口可以强制您进入全屏模式,锁定鼠标指针,并在未经您许可的情况下开始播放广告。

回答by jsSn0wMan

Was trying to do this myself then I came to this site Fullscreen API Phishing Attacks

试图自己做这件事然后我来到了这个网站Fullscreen API Phishing Attacks

Basically, if fullscreen mode was allowed onload, we don't know if site is actual website...fake site can have the lock logo saying it's safe, etc.

基本上,如果允许全屏模式加载,我们不知道网站是否是实际网站……假网站可以有锁标志,表示它是安全的,等等。