是否可以使用 JQuery 或 JavaScript 更改窗口大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7649574/
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
Is it possible to change window size with JQuery or JavaScript?
提问by Programmer
I will create 5 buttons. Example:
我将创建 5 个按钮。例子:
Button1's value : 640*480
Button2's value : 1024*600
Button3's value : 1600*900
Button4's value : 800*600
If the user clicks a button, I want it to change the browser window's size. I would like to do this via JQuery but JavaScript is fine too.
如果用户单击按钮,我希望它更改浏览器窗口的大小。我想通过 JQuery 做到这一点,但 JavaScript 也很好。
EDIT:
编辑:
And how can i change windows' position for computer's screen. Third question :) how can i create random number?
以及如何更改计算机屏幕的窗口位置。第三个问题 :) 如何创建随机数?
回答by epascarello
window.resizeTo()and window.moveTo()
window.resizeTo()和window.moveTo()
function changeSize( w, h){
window.resizeTo(w,h);
}
function movePosition( x, y){
window.moveTo(x,y);
}
Modern day browsers have settings that can prevent you have changing/moving/resizing the browser window.
现代浏览器的设置可以防止您更改/移动/调整浏览器窗口的大小。
[EDIT] Get yourself a good JavaScript reference. Math.random
[编辑] 给自己一个好的 JavaScript 参考。数学随机
回答by please delete me
In addition to epascarello's answer.
除了 epascarello 的回答。
var randomnumber=Math.floor(Math.random()*11)
That's the code for a random number between 0 and 10. Change 11 to whatever you want for an increased/decreased range.
这是 0 到 10 之间随机数的代码。将 11 更改为任何您想要的增加/减少范围的代码。