Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Close pop up window


Message #1 by "Cheng Kok Wai" <kwcheng@i...> on Wed, 26 Jun 2002 16:18:17 +0800
Hi Cheng,

> lets say i have a form which lists the records from a table. when i click
> the link on the id of the record,  i use window.open function in
javascript
> to pop up a window to show the details of that record. i can have multiple
> pop up at the same time. example, i want to see, record 1,5,6,18,22, i
will
> click the id (one by one click), and i will have 5 pop up window. hope u
> understand till this part. should be no problem right. now comes the
killer.
> lets say on the form, i click a close button or i click a button to go to
> another page or i click the "X" button on the top right corner of IE, how
do
> i automatically closes the 5 pop up window as well without having to press
> the close button on each pop up window?

One way to do it would to be to create create a global array to contain
references to all windows opened, then loop through the array and close the
windows when the body's onunload event is fired, something like...

<html>
<head>

<script>
var myWindows=new Array()

function OpenWindow(Id){
 myWindows[myWindows.length]=window.open("scrap.asp?id=" + Id, Id);
}

function CloseWindows(){
 for(var a=0; a<myWindows.length; a++){
  if(!myWindows[a].closed){
   myWindows[a].close();
  }
 }
}

</script>


</head>
<body onunload='CloseWindows();'>

<a href='javascript:OpenWindow(1);'>1</a><br>

<a href='javascript:OpenWindow(2);'>2</a><br>

<a href='javascript:OpenWindow(3);'>3</a><br>

</body>
</html>

HTH,

Chris


  Return to Index