More Window Methods

You've seen four window methods so far: open(), close(), focus(), and blur(). Let's look at two more that come in handy from time to time: resizing and moving windows.

Resizing Windows

Modern browsers provide two different ways your JavaScript can resize a window. The window.resizeTo() method resizes a window to a given width and height. To change a small window into one that's 500 pixels wide and 200 pixels high, you'd use the following script:


Alternatively, you can change the size of a window by a specific amount using window.resizeBy(). The window.resizeBy() method takes two numbers: how much the width of the window should change and how much the height should change. The code

window.resizeBy(10, −5); ...

Get The Book of JavaScript, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.