Closing a Window

Just as you can create windows, you should know how to get rid of windows by closing them. In Script 6.8, the parent window has “open” and “close” links that create and close the child window, and each link has a unique id that we use in the script. The external JavaScript is in Script 6.9.

To close a window:

1.
var newWindow = null;
This line initializes the value for the newWindow object that we’re going to use later. While most browsers do this automatically, some don’t, so it needs to be set here to avoid errors later.
2.
document.links[i].onclick = chgWindowState;
In the newWinLinks() function, we’re stepping through the links in the document as usual. The only difference here is that we’ll call chgWindowState() if we detect ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh 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.