tags:

views:

718

answers:

5

Well the title says it all is there any way to set the minimum size of a popup window?

Edit: My problem is that when some one and makes it as small as he can the content just looks stupid...

+1  A: 

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.

peirix
Would assign thise function to onresize as well...
Tracker1
this does not seem to do any thing at all even if i assign it to onresize...
Petoj
that's because I totally misunderstood the question. Sorry. Fixed, and should work now.
peirix
+1  A: 

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.

TheTXI
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
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.
TheTXI
A: 

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.

Gabri van Lee
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.
TheTXI
A: 

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.

jhornnes
A: 

Most browsers have a minimum width and height.

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

Jorge