Resizing a window

JavaScript FAQ | JavaScript Windows FAQ  

This page discusses obsolete browsers (IE4 and Netscape Navigator 4).
Here is an update on the window.resizeTo() method in modern browsers.

Question: How do I resize a window?

Answer: In Netscape Navigator 4 or Internet Explorer 4, you can resize the browser window by using the methods window.resizeTo(newWidth,newHeight) or window.resizeBy(DX,DY).

Note, however, that older browsers do not support these methods. The best course of action here is probably "do nothing in an old browser". For example, this code will resize the window to 600x400 in newer browsers, without causing errors in old browsers:

if (parseInt(navigator.appVersion)>3)
  top.resizeTo(600,400);
Note also that the parameters of resizeTo() have different meaning in different browsers: in Internet Explorer the parameters specify the outer size of the window, while in Netscape Navigator they refer to the inner size (which does not include the window borders, toolbar, status bar, title bar, and the address line). To resize the window to the same outer size in both browsers, you can use this function:
function resizeOuterTo(w,h) {
 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    top.outerWidth=w;
    top.outerHeight=h;
   }
   else top.resizeTo(w,h);
 }
}

See also:

  • Using the window.resizeTo() method in modern browsers
  • Copyright © 1999-2011, JavaScripter.net.