使用 JavaScript 在浏览器中触发全屏

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

Triggering full screen in browser with JavaScript

javascriptjquery

提问by Leon

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

可能的重复:
如何在 Javascript 中制作全屏窗口(在整个屏幕上拉伸)

Currently I tried to do something like, when you click a fullscreen button current window will become full screen. I tried to use the following script, but it doesn't work. Any ideas on how to make this work?

目前我尝试做类似的事情,当您单击全屏按钮时,当前窗口将变为全屏。我尝试使用以下脚本,但它不起作用。关于如何使这项工作的任何想法?

<script type="text/javascript">
window.onload = maxWindow;

function maxWindow() {
    window.moveTo(0, 0);

    if (document.all) {
        top.window.resizeTo(screen.availWidth, screen.availHeight);
    }
    else if (document.layers || document.getElementById) {
        if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
}
</script>

回答by Alnitak

There's a new API supported by some of the newer browsers that'll let you make any element take over the whole screen:

一些较新的浏览器支持一个新的 API,可以让任何元素占据整个屏幕:

See http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/for more info, including a jQuery plugin to use the feature.

请参阅http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/了解更多信息,包括使用该功能的 jQuery 插件。

回答by Roman

window.resizeTo has been disabled in modern browsers. You can only use it on your own popup windows.

window.resizeTo 在现代浏览器中已被禁用。您只能在自己的弹出窗口中使用它。

https://hacks.mozilla.org/2011/09/whats-new-for-web-developers-in-firefox-7/states:

https://hacks.mozilla.org/2011/09/whats-new-for-web-developers-in-firefox-7/指出:

Web sites can no longer resize your main browser window

It's no longer possible for a web site to change the default size of a window in a browser, according to the following rules:

  1. You can't resize a window or tab that wasn't created by window.open.
  2. You can't resize a window or tab when it's in a window with more than one tab.

网站无法再调整主浏览器窗口的大小

根据以下规则,网站不再可能更改浏览器中窗口的默认大小:

  1. 您无法调整不是由 window.open 创建的窗口或选项卡的大小。
  2. 当窗口或选项卡位于具有多个选项卡的窗口中时,您无法调整窗口或选项卡的大小。