Click to See Complete Forum and Search --> : closing multiple pop ups
smoker2
04-10-2003, 03:07 PM
Hi, I have been trying to get 2 pop ups to close at the same time, called from one of the pop ups onUnload function.
I originally had both pop ups opened from the parent page, but after failing to get both to close when needed, I switched to getting the first popup to spawn the second popup, in the hope that it would give the first popup more control over the second ....!!
I have tried to tell the 1st popup to close the second using windowname.close() and opener.windowname.close() and parent.windowname.close() and nothing works.
Is this possible, or am I just stoopid ?
I don't have to put "javascript:windowname.close()" in an onUnLoad event do I ?
TIA
alan
<script>
var win;
var win2;
function openWin1(){win = window.open("file.html","win");}
function openWin2(){win2 = window.open("file2.html","win2");}
function Close1(win){win.close();}
function Close2(win2){win2.close();}
</script>
That'll probably work...
smoker2
04-11-2003, 12:33 PM
Thanks,
I have tried your code, and it works fine when opening the windows, but it doesn't work at all when trying to close the windows. The best I can get to happen is that the 1st window closes, but that still leaves the 2nd open.
Much scratching of head here :confused:
I am not trying to close the parent window here, just the popups.
I have a feeling that if I call the close functions from the parent window, I may get the desired result.
But unfortunately, that is not possible for the setup I am trying to achieve.
I have a main window with a link that opens the 2 popups.
The popups obscure the main window completely.
One part of the site is then displayed in the top popup and another part in the bottom popup.
Once the user has finished using the site, I want them to click a link in the top popup which will close both popups and just leave the main site window.
I'll keep hacking....
alan
smoker2
04-13-2003, 10:22 AM
Cracked it !
Or hacked it (whatever :cool: )
I had to change the order for opening the windows.
So, in order
1) the site index page has a link to open the popups
window.open('search.html', 'win2' , 'top=129,left=0,toolbar=no,status=yes,location=yes,scrollbars=yes,width=790,height=390')
2) When search.html loads, it loads the 2nd popup
window.open('login.htm', 'win' , 'top=0,left=0,toolbar=no,menubar=no,location=no,scrollbars=no,width=790,height=90')
3) The final page of the top popup (was login.htm) has a script in the head
function doLogoff()
{
self.opener.location.href="die.html";
var dummy = setTimeout("self.close()", 500);
}
This causes the original search.html popup (win2) to load a blank page which has this script in the head and is executed onLoad
function doLogoff()
{
var dummy = setTimeout("self.close()", 500);
}
And of course the top popup (win1) commited suicide after loading the killer page into win2
A bit of a hack but at least it works
:rolleyes:
alan