Javascript window.close Example
An example showing how to use Javascript's window.close function
Published Aug 4, 2005 by lobo235Last updated on Jul 3, 2007
If you have a popup window on your web page it's nice to give the user a link they can use to close the window so they aren't limited to just clicking the window's close button. Here is an example of how to use Javascript's window.close function to close the current window. All you need to do is add this link to your popup window and when the user clicks it the current window (or in this case, the popup) will close. You can also use this same technique with an image if you wanted to create one that said "close window" or something like that. Here is the HTML code for the link.
<a href="javascript:window.close();">Close Window</a>
So basically what happens is that the link calls the Javascript function window.close and that function closes the window. Make sense? Try adding it to your popup windows to make your web pages easier to navigate.
Update March 27th, 2007:
I have had some readers who have asked why window.close doesn't work on the main Firefox window. Firefox is more secure than IE in that it won't let javascript close a window that was not opened by javascript in the first place. So, a parent window cannot be closed by javascript in Firefox but any windows opened with javascript from the parent page can be closed with javascript. In Firefox the window.close function is usually used to close pop-up windows that were spawned with javascript. One good reason for this is that Firefox allows tabbed-browsing so if a script on a page were able to close the main parent window all the tabs could be lost which would frustrate the user.
0 comments for this article.
Javascript DOM insertAfter function
Useful Git Commands and Tips/Tricks
Resizing an Image Using PHP and the GD2 Library