Tutorial :Setting the minimum size of a JavaScript popup window


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.


Most browsers have a minimum width and height.

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


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.


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.


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.



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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »