Resizing a window from JavaScript

JavaScript FAQ | JavaScript Windows FAQ  

Question: How do I resize a window?

Answer: In most modern browsers, you can programmatically resize the browser window by using the method

window.resizeTo(newWidth,newHeight)
. Prior to resizing the window, your script can check the current width and hight using
window.outerWidth
and
window.outerHeight
, respectively. (Internet Explorer does not support
outerWidth
/
outerHeight
; here is a partial workaround). Try resizing the window and checking
outerWidth
and
outerHeight
here:


Notes. Recent versions of Internet Explorer and Firefox allow you to resize the browser window that has only one open tab – but disallow the resizing of any window with two or more tabs. Google Chrome or Opera browsers may allow you to resize smaller script-generated windows – but disallow the resizing of the primary browser window. Here is what resizable script-generated windows look like in Opera 11 and Chrome 15:

Also, in some browsers the user can change the settings allowing JavaScript code to resize the browser window. For example, you can do so using these menus – see screenshots below:

  • in Firefox 3.x: the menu Tools > Options > Content > Advanced JavaScript Settings
  • in Opera 11: the menu Tools > Preferences > Content > JavaScript Options

Copyright © 1996-2018, JavascriptFAQ.net.