[Home]Close a window

HomePage | RecentChanges | Preferences | Newbie Help

Category HTML FAQ -:- [Category JavaScript FAQ]?

You can only close windows that you have opened with a JavaScript routine. Otherwise you get a warning dialog box from the browser.

Close window with text

<A HREF="#" onClick="window.close(); return false">Close Window</a>

Close window with a button

<input type=button value="Close Window" onClick="window.close()">

Close window with timer (time in milliseconds, 1000 = 1 second)

<SCRIPT TYPE="text/javascript">
<!-- BEGIN
timer = setTimeout("window.close()",1000);
// END -->
</SCRIPT>


Comments --

Note that it's probably a good idea to enclose links/buttons that use "window.close" in the JavaScript document.write('') statement, so that browsers that don't support JavaScript (and hence will be unable to close the window on the click of the link) will simply ignore the link/button altogether.

HomePage | RecentChanges | Preferences | Newbie Help
This page is read-only | View other revisions
Last edited February 23, 2002 9:56 am (diff)
Search:

This FAQ is happily hosted by Betadome Digital Media