Popup Close Methods
Go to www.cgiscript.net for more free tools!

Here you will find a few methods to close windows. Select from the list below to jump to the code. Use the instructions near each method.

Timer

Description:
Use this code to get a popup window to close after a pre-determined amount of time. For example, set an advertisement popup window to remain open for 15 seconds, then it automatically closes.

Directions:
Follow Steps 1 and 2 below. Use the 'Grab Text' buttons to select the code within the adjacent textarea. Then use Control-C or Edit -> Copy to buffer the text for pasting into your document.

Step 1: This code is placed between the <head> and </head> tags within the window that is opened (the popup window).

The length of time you want the window to remain open is set with the variable StayAlive.

Then use Control-C to copy the text into your web page.

Step 2: Add the following code to the <BODY> tag of the popup window. ( ex. <body onload="KillMe();self.focus()"> )
Note:
self.focus() ensures the popup window appears on top of all other windows.

Then use Control-C to copy the text into your web page.

Link

Description:
To get a popup window to close it is common to add a link that will allow the user to "Close Window".

Directions:
Below you will find the code required to create a "Close Window Link". You can change the text of the link by editing the "Close Window" to say whatever you would like. Use the 'Grab Text' buttons to select the code within the adjacent textarea. Then use Control-C or Edit -> Copy to buffer the text for pasting into your document.

Close Window Link: Insert the following code between the <BODY> and </BODY> tags of the popup window.

Then use Control-C to copy the text into your web page.

Button

Description:
To get a popup window to close it is common to add a button that will allow the user to "Close Window".

Directions:
Below you will find the code required to create a "Close Window Button". You can change the text of the button by editing the "Close Window" to say whatever you would like. Use the 'Grab Text' buttons to select the code within the adjacent textarea. Then use Control-C or Edit -> Copy to buffer the text for pasting into your document.

Close Window Button: Insert the following code into the popup window where you want the link.

Then use Control-C to copy the text into your web page.

Image

Description:
To get a popup window to close it is common to add an image link that will allow the user to "Close Window".

Directions:
Below you will find the code required to create a "Close Window Image". You can use whatever image you would like. Use the 'Grab Text' buttons to select the code within the adjacent textarea. Then use Control-C or Edit -> Copy to buffer the text for pasting into your document.

Close Window Image: Insert the following code between the <BODY> and </BODY> tags of the popup window.

Then use Control-C to copy the text into your web page.

Click Anywhere

Description:
A not so common method to close windows is using a 'click anywhere' method. The code specifies that if the popup loses focus or is clicked the popup closes. Basically anywhere you click will close the window.

Directions:
Below you will find the code required to create a "Click Anywhere". Use the 'Grab Text' buttons to select the code within the adjacent textarea. Then use Control-C or Edit -> Copy to buffer the text for pasting into your document.

Close Window - Click Anywhere: Insert the following code into your BODY tag of the popup window. Then all the user has to do is click anywhere on the screen to close the window.

Example: <body onBlur="self.close()" onClick="self.close()">

Then use Control-C to copy the text into your web page.