Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parent_Child connected Windows Closing !! 1

Status
Not open for further replies.

olegkot

Programmer
Aug 28, 2001
31
IL
Hi!

I have several windows in the Hierarchial relaitonship:
win4 = win3.open(); win3 = win2.open(); win2 = win1.open();
win1 = win.open().

I'd like to close all the child windows at any level of this Hierarchy. (if I close win2 -> the win3 and win4 have to be closed also).

Any ideas...
Thx, oleg
 
hie again
i think it have to be smth like the following:
~~somewhere in ur win4 (main window)
..
onunload=function(){
if (window.win3){
//if exists win3 (if u have opened a child window thru var win3=window.open())
if (win3.win2){//same thing
if (win3.win2.win1){
win3.win2.win1.close()
} win3.win2.close()
} win3.close()
} top.close()
}

sorry, i havent tryed it myself yet, i'll give it a try & tell'ya if its ok.. Victor
 
Thx!

and what about middle level windows (win3, win2)... Can I use the same schema from their level?

oleg
 
yeah, i think u can..
but only down the hierarchy & the current window opener, if u kno what i mean..

but u ofcourse can set ur own variables plus to window.opener:

var ancient=opener.opener or smth like that.. play around, u'll like it :) Victor
 
I tried, but the only main window is closing its chield win1. And after the process stops. Two more windows win2 and win3 are in the air.:-(


oleg
 
just like i wrote u, i havent tryed it myself yet but now i'm fixin it.. wuld let u know if i'll kill the buggs Victor
 
got it to work
i'm a bug killa!! B-)

u have 2 make win1..win4 global variables, but not define'em in the functions..

take a look at my files:

win4.htm
~~~~~~~~~
<html>
<head>
<title>win4</title>
<script>
var win3

function op(){
win3=open('win3.htm','','')
}
function cl(){
if (window.win3){
if (win3.win2){
if (win3.win2.win1){
win3.win2.win1.close()
} win3.win2.close()
}
win3.close()
}
// top.close()
}


//onunload=cl

</script>
</head>

<body bgcolor=&quot;#FFFFFF&quot;>
<input type=button value=open onclick=&quot;op()&quot;><br>
<input type=button value=&quot;close children&quot; onclick=&quot;cl()&quot;><br>

</body>
</html>
~~~~~~~~~



win3.htm
~~~~~~~~~
<html>
<head>
<title>win3</title>
<script>
var win2
function op(){
win2=open('win2.htm','','')
}
function cl(){
if (window.win2){
if (win2.win1){
win2.win1.close()
} win2.close()
} top.close()
}


//onunload=cl

</script>
</head>

<body bgcolor=&quot;#FFFFFF&quot;>
<input type=button value=open onclick=&quot;op()&quot;><br>
<input type=button value=&quot;close children&quot; onclick=&quot;cl()&quot;><br>

</body>
</html>
~~~~~~~~~



win2.htm
~~~~~~~~~
<html>
<head>
<title>win2</title>
<script>
var win1
function op(){
win1=open('win1.htm','','')
}
function cl(){
if (win1){
win1.close()
} top.close()
}


//onunload=cl

</script>


</head>

<body bgcolor=&quot;#FFFFFF&quot;>
<input type=button value=open onclick=&quot;op()&quot;><br>
<input type=button value=&quot;close children&quot; onclick=&quot;cl()&quot;><br>

</body>
</html>
~~~~~~~~~



win1.htm
~~~~~~~~~
~whatever
~~~~~~~~~ Victor
 
Hi Victor!
Thx for your help!

Another question conserning the same subject:

When I refresh one of my chield windows (win2), then I can't fire the close action to it (win2) from its parent (win3) as no connection between them.

Have you got any ideas to prevent this situation?

oleg.
 
hi Oleg
just tryed your situation with win4->win3 windows.. looks like it works.. here is how i did it:
window win4 - stays the same, but you could include reload feature there too..

(btw, here is an answer to your another question, about reloading-and-not-closing the window)

<html>
<head>
<title>win3</title>
<script>
//theFlag - flag to know if you're reloading or not, false -
//you aren't reloading, & page should be closed

var win2,theFlag=false

//these functions you have seen before :)
function op(){
win2=open('win2.htm','','')
}

function cl(){
if (window.win2){
if (win2.win1){
win2.win1.close()
} win2.close()
} top.close()
}


//this one is new - 'reloader' you see how it works..
function rl(){
theFlag=true
top.location.reload(true)
}

//a bit modifyed unload handler..
onunload==function(){
if (!theFlag) cl()
}

</script>
</head>

<body bgcolor=&quot;#FFFFFF&quot;>
<input type=button value=open onclick=&quot;op()&quot;><br>
<input type=button value=&quot;close children&quot; onclick=&quot;cl()&quot;><br>
<input type=button value=&quot;reload&quot; onClick=&quot;rl()&quot; name=&quot;button&quot;><br>
</body>
</html>
Victor
 
Victor!

When I reload parent page using &quot;Reload&quot; button, the &quot;close children&quot; button is not closing the chield window.

I tried to modify reload method (as you've done with onunload) but it puts me to the endless loop onunload-reload-onunload.

<html>
<head>
<title>win2</title>
<script>
var win1,theFlag=false

function op(){
win1=open('win1.html','win1','')
}

function cl(){
if (win1){
win1.close()
} top.close()
}

function rl(){
theFlag=true
top.location.reload(true)
}

onunload=function(){
if (!theFlag) cl()
}

//reload=function(){
//rl()
//theFlag=true
//top.location.reload(true)
//}

//onunload=cl

</script>


</head>

<body bgcolor=&quot;#FFFFFF&quot;>
<input type=button value=open onclick=&quot;op()&quot;><br>
<input type=button value=&quot;close children&quot; onclick=&quot;cl()&quot;><br>
<input type=button value=&quot;reload&quot; onClick=&quot;rl()&quot; name=&quot;button&quot;><br>

</body>
</html>

thx in advance, oleg.
 
ok, now i got it: you meant that after reload you can't close this window's children but not this window itself, right?

if so, here is a small addition:
this fnction is for win3, & it checks with interval of 100 miliseconds if it's opener was reloaded (& thy lost it's variable win3), & if it was, it assigns itself to this variable (woo - i guess i can repeat that :)).. i guess.. )

function antiforget(){
if (!opener.win3) opener.win3=top
}
var timer=setInterval('forgetable()',100)

& you can stop this reminder any time using
clearInterval(timer)

Victor
 
oops! correction:

function antiforget(){
if (!opener.win3) opener.win3=top
}
var timer=setInterval('antiforget()',100) :))

another one:

you should use

if (window.win3 && !window.win3.closed){..

instead of previously used

if (window.win3){..

it would prevent you from getting errors when user would close childs handy.. Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top