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.

Get jQuery and JavaScript Phrasebook 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.