Just as you use window.open() to open a window, you use window.close() to close it.
The part of closing windows that causes the greatest confusion is that simply calling window.close() seldom does actually close the current window. The reason for this is that JavaScript can only close windows opened by JavaScript and so if the current web page was not loaded into the window using a window.open call then the window.close will NOT close the window.
The only other place where a window opened by JavaScript can be closed is from the page that opened it. The following example shows how we can retain a pointer to the new window from within the page opening it so as to be able to close it again from within the same page.
var mywin; newwin = function(page) {
return window.open(page,'javascriptabout',,true);
}
mywin = newwin('next.htm');
mywin.close();
