1

Is there any way to set the minimum size of a popup window through JavaScript?

My problem is that when someone makes it as small as he can the content just looks stupid.

5 Answers 5

3

When creating pop-ups, you can only set width and height. But since the pop-up was created, it means you can change the height and width of the window when the pop-up loads. Simply place an onload event inside your pop-up window:

window.onload = function() {
  if (document.body.scrollHeight) {
     var winWidth = document.body.scrollWidth;
     var winHeight = document.body.scrollHeight;
  } else if (document.documentElement.scrollHeight) {
     var winHeight = document.documentElement.scrollHeight;
     var winWidth = document.documentElement.scrollWidth;
  } else {
     var winHeight = document.documentElement.offsetHeight;
     var winWidth = document.documentElement.offsetWidth;
  }
  window.resizeTo(winWidth, winHeight);
}

edit: Tested in IE7,8, Chrome, Safari 4, Firefox 3. Working, but you might need to take into account the size of menu+address bars and such, as the window size will be the outer size, and this function will find the size of the content. So to be safe you should probably add a couple of pixels, and also turn off scrollbars in the popup to make sure they won't take up any space.

Sign up to request clarification or add additional context in comments.

1 Comment

that's because I totally misunderstood the question. Sorry. Fixed, and should work now.
1

I do not believe that you can set a minimum using the Javascript new window. I know you can set the size and disable the scroll bars and prevent resizing, but that would answer the minimum, but also impose a maximum as well, which you may not be wanting.

2 Comments

Setting resizing=no seems to do the trick in moste browsers but Only IE seems to care about it the rest(Opera, FF, Chrome, Safari) ignore it!
Petoj: First off, you are ignoring about 25% of the browser market share by doing that. Secondly...setting resize to 0 would prevent them from expanding it as well as minimizing it. If you are fine with that, that's all good. I was only tossing that out there in case you wanted them to have the option to expand but not to resize smaller.
0

Most browsers have a minimum width and height.

Internet Explorer 7 minimum width > 250px minimum height > 150px

1 Comment

Just FYI, Chrome v79 does not have any minimum window sizes.
0

When using windows.open, you can specify the height and width of the window like this:

window.open ("http://www.stackoverflow.com", "mywindow","menubar=1,resizable=1,width=350,height=250");

It is not the minimum size though, as the window will not be bigger when there is more room. You would have to check screen space yourself for that.

1 Comment

Another thing to note: if you have resizable set to 1, it would still allow someone to resize it smaller, bypassing the minimum you may have wanted. This may depend a lot of what the author considers "minimum" to be.
0

http://www.htmlgoodies.com/beyond/javascript/article.php/3471221

As seen in the link, you can set the minimum size. If you want to scale it so it gets bigger you must to that from within the popupwindow.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.