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:

window.resizeTo(500,200);

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.