Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Closing several windows, open or not

    I've used javascript in links on one page to open several small windows. At the bottom of the page is a link which I desire to close all of the small windows I've opened. Currently, I am using the code:

    function close_all()
    {
    win1.close()
    win2.close()
    win3.close()
    win4.close()
    win5.close()
    }

    ... which only works if all windows are open. If the user has decided to open only windows 1,2,4 and 5, the link at the bottom only closes 1 and 2, leaving 4 and 5 open. If any of you know a method of closing all windows, regardless of user actions, please assist me.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    try:

    if(win1!=null){
    win1.close()
    }
    if(win2!=null){
    win2.close()
    }
    ...

    You may use a loop to shorten the code, I guess...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thank you. That worked brilliantly.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    function close_all()
    {
      var w;
      for (var i=1; i<=5; i++) {
         w = window["win" + i];
         if (w && !w.closed) w.close();
      }
    }

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    yeap Glenn, that's the loop
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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