Javascript 设置浏览器窗口大小

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

Javascript set browser window size

javascripthtmlbrowserwindow-resize

提问by Web_Designer

What is the best way to set the size of the browser window when the page loads? I think this can be done in JavaScript. Please explain. Here is my code that is not working!

页面加载时设置浏览器窗口大小的最佳方法是什么?我认为这可以在 JavaScript 中完成。请解释。这是我的代码不起作用!

<html>
<body onload="window.resizeTo(640,480)">
<video src="rushmore.mp4" controls="controls">
your browser does not support the video tag
</video>
</body>
</html>

采纳答案by Dustin Laine

I put this in an answer as the comment became to long.

随着评论变得很长,我把它放在了一个答案中。

The only thing that I have found that is close to the resizing of the chrome window is to use a chrome extension that can resize the window. The actual extension command is chrome.windows.update(...).

我发现唯一接近调整 chrome 窗口大小的方法是使用可以调整窗口大小的 chrome 扩展。实际的扩展命令是chrome.windows.update(...).

Take a look here.

看看这里

But I am not sure this is what you are looking for.
If it still interests you there are at least 2 extensions that can do this, that I have seen try this one

但我不确定这就是你要找的。
如果您仍然感兴趣,至少有 2 个扩展可以做到这一点,我见过尝试这个

Be happy and good luck!

祝你幸福和好运!

回答by Dustin Laine

This should do the trick, setting the height and width to your desired dimensions.

这应该可以解决问题,将高度和宽度设置为您想要的尺寸。

window.resizeTo(500,500)

You could set it onload.

你可以设置它onload

<body onload="window.resizeTo(500,500)">