Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > close all child windows when close the main window

Reply
Thread Tools

close all child windows when close the main window

 
 
jrefactors@hotmail.com
Guest
Posts: n/a
 
      01-15-2005
>From the main page, there are lots of links to open new window.
i.e. <a href="#" onClick="window.open('child1.html')">Open Child
Window</a>

If I close the main page, I want to close all child windows also. That
means I
need to keep track all handles of the child windows whenever I open a
new
window. Correct? any suggestions on the approach?
Please advise. thanks!!

 
Reply With Quote
 
 
 
 
porneL
Guest
Posts: n/a
 
      01-15-2005

> If I close the main page, I want to close all child windows also. That
> means I need to keep track all handles of the child windows whenever I
> open a
> new window.


That won't work if user browses in main window.

IMO the best way is to simply add 'dependent=yes' to popup window
attributes.
Doesn't work everywhere, but when works - it works

BTW: never use href="#", put real address there and use return false in
onclick.
This will improve search engine visibility, ensure that windows open in new
window, links can be copied/bookmarked, etc.

--
* html {redirect-to: url(http://browsehappy.pl);}
 
Reply With Quote
 
 
 
 
Chung Leong
Guest
Posts: n/a
 
      01-16-2005
<> wrote in message
news: oups.com...
> >From the main page, there are lots of links to open new window.

> i.e. <a href="#" onClick="window.open('child1.html')">Open Child
> Window</a>
>
> If I close the main page, I want to close all child windows also. That
> means I
> need to keep track all handles of the child windows whenever I open a
> new
> window. Correct? any suggestions on the approach?
> Please advise. thanks!!
>


Yes. Wouldn't be hard if you define a Javascript function for opening
windows and save the handles into an array.

Or you could use the ShowModelessDialog() function. Modless dialog boxes
stay in front of their parent window and automatically would close when the
parent closes.


 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      01-16-2005
Chung Leong wrote:
> <> wrote in message
> news: oups.com...
>
>>>From the main page, there are lots of links to open new window.

>>i.e. <a href="#" onClick="window.open('child1.html')">Open Child
>>Window</a>
>>
>>If I close the main page, I want to close all child windows also. That
>>means I
>>need to keep track all handles of the child windows whenever I open a
>>new
>>window. Correct? any suggestions on the approach?
>>Please advise. thanks!!
>>

>
>
> Yes. Wouldn't be hard if you define a Javascript function for opening
> windows and save the handles into an array.
>
> Or you could use the ShowModelessDialog() function. Modless dialog boxes
> stay in front of their parent window and automatically would close when the
> parent closes.


Modeless Dialogs are also IE-only.

I might be able to understand the OT if this were not posted to
comp.lang.javascript


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
 
Reply With Quote
 
Chung Leong
Guest
Posts: n/a
 
      01-16-2005
"Randy Webb" <> wrote in message
news:ioednbf4RczSbHTcRVn-...
> Chung Leong wrote:
> > <> wrote in message
> > news: oups.com...
> >
> >>>From the main page, there are lots of links to open new window.
> >>i.e. <a href="#" onClick="window.open('child1.html')">Open Child
> >>Window</a>
> >>
> >>If I close the main page, I want to close all child windows also. That
> >>means I
> >>need to keep track all handles of the child windows whenever I open a
> >>new
> >>window. Correct? any suggestions on the approach?
> >>Please advise. thanks!!
> >>

> >
> >
> > Yes. Wouldn't be hard if you define a Javascript function for opening
> > windows and save the handles into an array.
> >
> > Or you could use the ShowModelessDialog() function. Modless dialog boxes
> > stay in front of their parent window and automatically would close when

the
> > parent closes.

>
> Modeless Dialogs are also IE-only.
>
> I might be able to understand the OT if this were not posted to
> comp.lang.javascript


Oops. Why did the OP cross post into comp.lang.php?


 
Reply With Quote
 
sateeshranga sateeshranga is offline
Junior Member
Join Date: Aug 2008
Posts: 2
 
      08-07-2008
Main.html

<html>
<head>
<script>
var wnd = new Array();
function openit(id)
{
if(!wnd[id] || wnd[id].closed)
wnd[id] = window.open("Child.html");
else
wnd[id].focus();
}

function closeEverything()
{
for(var i = 0; i < wnd.length; ++i)
wnd[i].close();
}
</script>
</head>
<body>
<form>
<input type="button" value="Open1" onclick="openit(0);" /><br/>
<input type="button" value="Open2" onclick="openit(1);" /><br/>
<input type="button" value="Open3" onclick="openit(2);" /><br/>
</form>
</body>
</html>

Child.html

<html>
<head>
<script>
function closeAll()
{
window.opener.closeEverything();
}
</script>
</head>
<body>
<form>
<input type="button" value="Close Me" onclick="window.close();" /><br/><br /><br />
<input type="button" value="Close all children" onclick="closeAll();" /><br/>
</form>
</body>
</html> Main.html

<html>
<head>
<script>
var wnd = new Array();
function openit(id)
{
if(!wnd[id] || wnd[id].closed)
wnd[id] = window.open("Child.html");
else
wnd[id].focus();
}

function closeEverything()
{
for(var i = 0; i < wnd.length; ++i)
wnd[i].close();
}
</script>
</head>
<body>
<form>
<input type="button" value="Open1" onclick="openit(0);" /><br/>
<input type="button" value="Open2" onclick="openit(1);" /><br/>
<input type="button" value="Open3" onclick="openit(2);" /><br/>
</form>
</body>
</html>

<strong class="highlight">Child</strong>.html

<html>
<head>
<script>
function closeAll()
{
window.opener.closeEverything();
}
</script>
</head>
<body>
<form>
<input type="button" value="Close Me" onclick="window.close();" /><br/><br /><br />
<input type="button" value="Close all children" onclick="closeAll();" /><br/>
</form>
</body>
</html>
 
Reply With Quote
 
sateeshranga sateeshranga is offline
Junior Member
Join Date: Aug 2008
Posts: 2
 
      08-07-2008
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<style type="text/css">

input {
width: 80px;
font-size: 75%;
background: beige;
padding: 2px;
margin: 2px;
}

</style>
<script type="text/javascript">

function popit(n)
{
var w, wname = 'pop' + n;
var l = 100 * n + 100;
var t = 100 * n + 100;
w = window.open('javascript:"<h4>'+wname+'</h4>"',
wname,
'width=200,height=200,left='+l+',top='+t+',status= 0');
addName(wname);
return false;
}

function addName(wname)
{
self.name += (wname + '@');
}

function closeByName(wname)
{
window.open('javascript:"<script>window.close()<\/script>"', wname);
}

function closeAll()
{
var wname,
wcoll = self.name.split('@');
self.name = '';
for (var i = 0, l = wcoll.length; i < l; ++i)
if (wname = wcoll[i])
closeByName(wname);
return false;
}

</script>
</head>
<body>
<form>
<input id="w1" type="button"
value="open pop 1"
onclick="popit(1)" />
<br />
<input id="w2" type="button"
value="open pop 2"
onclick="popit(2)" />
<br />
<input id="w3" type="button"
value="open pop 3"
onclick="popit(3)" />
<br /><br />
<input id="ca" type="button"
value="close all"
onclick="closeAll()" />
</form>
</body>
</html>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling function in a child window from main parent window Bhishm Javascript 2 09-03-2007 11:08 PM
Calling function in a child window from main parent window Bhishm ASP .Net 2 09-03-2007 07:22 PM
need to close main window on child opens succesfully Jaggu Javascript 7 05-22-2006 12:38 PM
close all child windows when close the main window jrefactors@hotmail.com Javascript 3 01-16-2005 10:06 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM



Advertisments