how to open and close a new window with timed javascript?

Discussion in 'JavaScript' started by yhe, Mar 14, 2012.

  1. #1
    Hi guys!

    I need help with a javascript code...i don't know almost anything about java!

    this is the issue:

    i have this javascript code on a html page:

    
    
    <html>
    <head>
    <script type="text/javascript">
    function open_win() {
        window.open("http://yahoo.com");
    
        setTimeout("window.open('http://google.com')",60000);
        setTimeout("window.open('http://bing.com')",120000);
        setTimeout("window.open('http://aol.com')",180000);
      
    
    </script>
    
    </head>
    
    <body>
    <form>
    <input type=button value="Open Windows" onclick="open_win();">
    </form>
    </body>
    
    </html>
    
    
    
    
    Code (markup):
    When you click the button a new window will open, in this case Yahoo website, than after a minute the Google search page window, after 2 minutes the Bing page window and after 3 minutes the Aol page window.

    Of course this will works only if the popups are allowed for the website wich have the .html page!


    My problem:

    The javascript loads the new windows timed but i want each new opened window to self close until the next one is loaded! and all this from the original html page.

    Example: after a minute the Google page is loaded and i want the Google window to self close until the window with Bing website is loaded...let's say to close after 50 seconds after it opened!

    I hope you guys understand my problem and know how to resolve it!

    thanks in advance!
     
    yhe, Mar 14, 2012 IP
  2. blacknet

    blacknet Active Member

    Messages:
    709
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    70
    #2
    the second argument of the window.open function allows you specify a name for the window, use the same one and it'll use the same window, replacing the content in it - if it's been closed, it'll reopen a new window with the new address.

    Failing that, the window.open function returns a reference to the opened window, on which you can call the close() function. e.g.

    
     var x = window.open("http://...");
     x.close();
    
    Code (markup):
     
    blacknet, Mar 14, 2012 IP
  3. yhe

    yhe Active Member

    Messages:
    392
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    53
    #3
    thank you "blacknet" for your fast reply but like i said i dont't know almost anything about javascript!

    could you please edit the code i inserted in the first post...only for the the first timed window (wich opens google website in a new window) to see how to edit the rest of them?
     
    yhe, Mar 14, 2012 IP
  4. yhe

    yhe Active Member

    Messages:
    392
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    53
    #4
    anyone?? a working example?
     
    yhe, Apr 1, 2012 IP