SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot prashidi's Avatar
    Join Date
    Mar 2001
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    automatically close window

    Hi,
    Im wondering how I can automatically close a window after a few seconds.

    I know about

    <script type="text/javascript">
    window.self.close();
    </script>

    but i need some time for the site to do a query and then have it closed.
    Thanks
    Last edited by prashidi; Mar 1, 2003 at 23:40.

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put these two files in the same folder and load parent.html into your browser. You can't close the parent window without user confirmation. But you can close child windows.

    Code:
    <!-- parent.html -->
    
    <html>
    <head>
    <title>Parent</title>
    <script>
    window.onload = function() {
      window.open('child.html','x');
    }
    function WndTimeout(seconds) {
      setTimeout('onWndTimeout()', seconds*1000);
    }
    function onWndTimeout() {
      window.close();
    }
    </script>
    </head>
    <body>
    <h3>Parent</h3>
    <p><a href='javascript:WndTimeout(5)'>WndTimeout(5)</a></p>
    </body>
    </html>
    
    <!-- child.html -->
    
    <html>
    <head>
    <title>Child</title>
    <script>
    function WndTimeout(seconds) {
      setTimeout('onWndTimeout()', seconds*1000);
    }
    function onWndTimeout() {
      window.close();
    }
    </script>
    </head>
    <body>
    <h3>Child</h3>
    <p><a href='javascript:WndTimeout(10)'>WndTimeout(10)</a></p>
    </body>
    </html>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •