35

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.

Sanghyun Lee
  • 21,644
  • 19
  • 100
  • 126
  • 1
    What do you mean by "When a page is moved to another page"? – Shadow The GPT Wizard Aug 11 '11 at 08:17
  • 4
    Stop trying to annoy people. Thanks. – ThiefMaster Aug 11 '11 at 08:25
  • @ThiefMaster Not trying to annoy people. I just hope a website cant resize my browser because it is very annoying to the end user. – Michael Koper Aug 11 '11 at 08:29
  • @Shadow It means "When the URL of page is changed". Could you tell me how to describe this? – Sanghyun Lee Aug 11 '11 at 09:18
  • @Michael: It was directed to Sangdol since self-resizing browser windows are an annoyance. – ThiefMaster Aug 11 '11 at 09:42
  • Sangdol you mean you have pages on your site with fixed width and height, and you want to resize the whole window to fit exactly those dimensions in every page? – Shadow The GPT Wizard Aug 11 '11 at 09:53
  • @Shadow Yes. Mine has just two pages. First one is a sign in page. And second one is sending email page. I thought resize the window to fit dimensions of email form was looks good and not so annoying. But I may should do something else. – Sanghyun Lee Aug 11 '11 at 10:14
  • If it's only a small form, consider embedding it into the first page using jQuery plugin like `LightBox` to make it look nicer – Shadow The GPT Wizard Aug 11 '11 at 10:20
  • @Shadow The page should be redirected after the user sign in like the Facebook's `share` popup or Twitter's `tweet this blog` popup. – Sanghyun Lee Aug 11 '11 at 10:29
  • For most browsers you can do that only for a window you've created, I've addressed this issue here: http://stackoverflow.com/questions/5139323/window-resize-is-not-working-in-chrome-and-opera/35801906#35801906 – jave.web Dec 26 '16 at 19:14

4 Answers4

53

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.

Sanghyun Lee
  • 21,644
  • 19
  • 100
  • 126
7
<script type="text/javascript">
    function changeScreenSize() {        
        window.resizeTo(screen.width-300,screen.height-500)   
    }
</script>

<body onload="changeScreenSize()">
agf
  • 171,228
  • 44
  • 289
  • 238
Chhaya
  • 219
  • 3
  • 7
  • I havent tried it. But I guess it works. If not this then this definitly works window.open('html page',' ','width=750,height=300') – Chhaya Aug 11 '11 at 08:35
  • 6
    I voted your answer down because you proposed a solution and then admitted to not even trying it. – Markus Aug 22 '14 at 11:45
  • 21
    @Markus - did you try it to verify that it in fact doesnt work? cause it totally does. SO is about answers, not about work ethics. If Chhaya can answer correctly without testing his solution, i dont see why he shouldnt. you just made a correct answer sink to the bottom of the page for the sake of pettiness. im re-upvoting this. – katzenhut Sep 25 '14 at 12:16
  • 5
    +1 for @katzenhut. Just because you personally haven't used/tested a method doesn't change the rules that dictate whether or not it will function. Not ever saying a particular word doesn't change it's meaning. So offering a solution containing untested code, as long as it falls within the usage guidelines for that scripting language, doesn't mean the answer is any less valid or valuable, merely that it is based on intrinsic knowledge of the coding language instead of a personal case study. – MistyDawn Jul 09 '18 at 20:04
2

use

window.resizeBy(relativeW, relativeH);
sina72
  • 4,931
  • 3
  • 35
  • 36
2

Whilst you might technically be able to do this, you really shouldn't. forcing the size of the browser window fundamentally changes the browsing experience for a user which isn't your place to do. Very bad practise and poor user experience.

Edit: Interesting to still get comments on this, but to be clear this answer is 6 years old, which is an age in web development time. Rather than edit it in context or delete it, I would say that it is wise to investigate current web development UX practises.

Ira Rainey
  • 5,173
  • 2
  • 34
  • 42
  • 2
    I made a thread about this issue on ux.stackexchange.com. We may can discuss about this in here. http://ux.stackexchange.com/questions/9903/why-is-resizing-the-browser-window-bad-practice/9941#9941 – Sanghyun Lee Aug 12 '11 at 02:10
  • 34
    -1 Be careful when making judgements like this, there are cases in which you may still want to do this, for example to test the behaviour of controls during window resize in Continuous Integration testing environment. – Steven de Salas Jan 17 '12 at 16:29
  • 1
    Usage Case: I have to resize the window to get a properly formatted "full-size" screen capture of a webform page for a work project. Without resizing the window programmatically, I'm unable to force bootstrap to update the page layout for the capture. It's only momentary and is changed back to device-width and height after the capture. – MistyDawn Jul 09 '18 at 20:07
  • Another use case: I am creating a small browser game where pixel counting is necessary and changing the screen size would be ideal for there to be no value breaks and stuff ... – Andrei Coelho Apr 03 '20 at 21:57
  • Another use case: I want to [make a browser less fingerprintable by setting the window to a specific, generic size](https://security.stackexchange.com/questions/102133/how-can-you-be-tracked-using-screen-resolution-monitor-size-in-tor), as opposed to if I resize manually by just dragging the corner. – ᴍᴇʜᴏᴠ Jun 03 '20 at 06:20