Using the Right Name: How Windows See Themselves and Each Other

Every window is a bit egocentric and thinks of itself as window. Let's say you open a web page titled The Original Window. Now let's say that window opens a second window, new_window.html (titled The New Window), using JavaScript, like this:

var new_window =
    window.open("new_window.html","new_window","height=100,width=100");

These two windows see each other in different ways. The original window thinks the new window is called new_window. The new window, however, thinks of itself as window. This means if you want to close the new window using JavaScript inside the original window, you'd write this code:

new_window.close();

But to close the new window using JavaScript inside the new window, ...

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.