O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Opening and Closing Windows

//Opens a new blank window, writes to it, and then closes it. var newWindow = window.open(); newWindow.document.write("Hello From a New Window"); newWindow.close(); //Opens another URL in a new window window.open("http://google.com");

The window object also provides a set of methods that allow you to create and manage additional child windows from your JavaScript code.

For example, the window.open(URL) method opens a new window and returns a new window object. If you do not specify a URL, the browser opens a blank page that can be written to using the window.document object.

You can call .close() on window objects that you have created, and they will be closed.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required