Posted By

apphp-snippets on 03/04/13


javascript window close

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Close Window in JavaScript

 / Published in: Java


The function that closes window is very useful when you use a pop-up window on your page, because it allows the visitor to easily close the window. You can also do it several ways: to use a button, a text link or make the window closes automatically after a given number of seconds.

  1. <!-- Sample #1: form button -->
  2. <form>
  3. <input type=button value="Close This Window" onclick="javascript:window.close();">
  4. </form>
  6. <!-- Sample #2: text link -->
  7. <a href="javascript:window.close();">Click Here to Close Window</a>
  9. <!-- Sample #3: close window after a given number of seconds -->
  10. <body onload="setTimeout(window.close, 10000)">...</body>

Report this snippet  

You need to login to post a comment.