将浏览器全屏显示并在按钮单击时刷新(模拟 F11)JavaScript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18075636/
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-27 10:39:50  来源:igfitidea点击:

Put browser full screen and refresh on button click (simulate F11) JavaScript

javascriptfullscreenkeypress

提问by Amila

I went through more than 10 questions with same content but not to find a updated answer. (world of web is changing rapidly I guess). First thing is, is it possible to put current window full screen simulating F11 press on a user button click. also what is the best practice for doing it if I want the function to work in all major browsers (IE, FF, Chrome and Safari).

我经历了 10 多个内容相同的问题,但没有找到更新的答案。(我猜网络世界正在迅速变化)。首先,是否可以将当前窗口全屏模拟 F11 按下用户按钮单击。如果我希望该功能适用​​于所有主要浏览器(IE、FF、Chrome 和 Safari),那么最佳做法是什么。

How to make in Javascript full screen windows (stretching all over the screen)

如何在 Javascript 中制作全屏窗口(在整个屏幕上拉伸)

Simulate F11 with javascript

用javascript模拟F11

onclick go full screen

点击进入全屏

including above links I went through lot of questions but had no susses. Its really helpful if someone can come up with an idea. Thanks.

包括上面的链接,我问了很多问题,但没有问题。如果有人能提出一个想法,那真的很有帮助。谢谢。

采纳答案by ZaoTaoBao

回答by Luke

This question is possibly a duplicate of a question you linked to. The latest cross-browser solution is:

此问题可能与您链接到的问题重复。最新的跨浏览器解决方案是:

function requestFullScreen(elt) {
    console.log("Requesting fullscreen for", elt);
    if (elt.requestFullscreen) {
        elt.requestFullscreen();
    } else if (elt.msRequestFullscreen) {
        elt.msRequestFullscreen();
    } else if (elt.mozRequestFullScreen) {
        elt.mozRequestFullScreen();
    } else if (elt.webkitRequestFullscreen) {
        elt.webkitRequestFullscreen();
    } else {
        console.error("Fullscreen not available");
    }
}

Please note that this is "experimental technology" as of this post. See this answerand this MDN pagefor more details.

请注意,这是本文中的“实验技术”。有关更多详细信息,请参阅此答案此 MDN 页面