Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

javascript - Can I resize the browser window?

I want to resize a browser popup window's width and height. I can set the popup window size but I want to convert the window size fit to contents size when a page is redirected to another page.

I tried this:

$(window).width(1000);  // Not working.

How can I do this?

Update

Everybody told me not to do it. To find out the exact reason why this is bad practice, I asked on ux.stackexchange.com.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found some answers to this question. This question is duplicate. But I'll answer again because I'll integrate them and add some more information.

To resize the window, you can simply do this:

window.resizeTo(width, height);

But this method is not working in Chrome and Opera. How do you resize an IE browser window to 1024 x 768

The reason, from The javascript "resizeTo" function not working in Chrome and Opera, is:

The resizeTo method is disabled by default in several browsers, and I know that it can also be manually disabled in Firefox.

It has been widely misused, so most browser vendors feel that it should be disabled, or at least a user controllable option.

But the method is working on popups even in Chrome or Opera. I guess the reason is that the browser vendors thought the resizeTo method could be needed in popups, and I think so.

To discuss this I made a thread about this issue on ux.stackexchange.com. https://ux.stackexchange.com/questions/9903/why-is-resizing-the-browser-window-bad-practice/9962#9962

I'm not sure if the resizeTo method is evil in every case but I'm sure that one should be careful when using this method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...