Chapter 11. Scripting Windows

Dialog boxes and the location object are far from all the window object has to offer developers. In fact, this object is often used to open and manipulate new windows.

OPENING NEW WINDOWS

Even though the advent of pop-up blockers greatly (and rightly) diminished the use of opening new windows through script, you can still find the practice legitimately used by many web-based applications. The key to this functionality is the open() method. It accepts four optional arguments, and returns the window object of the newly created window (dubbed the child window in this text).

The first parameter of the method is the URL of the web page you want to open in the child window; passing an empty string causes the child window to open a blank page. The second parameter, if specified, is the name you want to give to the new window. This name corresponds with the value given to the target attribute in hyperlinks. The following HTML is an example:

<a href="http://www.microsoft.com" target="childWindow">Microsoft.com</a>

If you were to open a new window with JavaScript and give it the name childWindow, clicking this link would load www.microsoft.com in the newly opened window. Of course, omit the second parameter if you do not wish the window to be a target for links.

The third parameter is a list of options and properties that determine how the child window looks. These options and properties include, but are not limited to, width, height, and whether user interface elements ...

Get JavaScript® 24-Hour Trainer 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.