1. Home
  2. Computing & Technology
  3. JavaScript

Popup Windows

4. Timed Window Close

clr gif

In the last tutorial we saw how we could set up a new window to popunder when it was first created and then popup after a set time period. We also saw in the first tutorial how we could add a close link to the popup window to allow our visitors to close the window by selecting a link within the window.

We can easily combine these two pieces of code to make the window close itself automatically after a certain time has elapsed. The code that we would use to do this is as follows if placed in the code in the main window:

setTimeout('TheNewWin.close();',30000);

or like this if added to the popup/popunder window itself:

setTimeout('self.close();',30000);

In both examples I have used 30 seconds (30000 milliseconds) as the delay before closing. You can easily change this to whatever amount of time (in thousandths of a second) that you require.

Explore JavaScript

More from About.com

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Windows and Frames
  5. Popup Windows
  6. Timed Window Close

©2008 About.com, a part of The New York Times Company.

All rights reserved.