BNBJ
asked on
How do I detect if window.opener is still there?
I have a page (Page A) that opens a popup (Page B).
There is a link on Page B that needs to check whether Page A still exists. If it does it needs to run...
window.opener.location.hre f = 'test.htm';
If the opener page doesn't exist then I need to run...
window.open('test.htm');
How can I detect whether the opener is still there.
I've tried...
if(!window.opener){
window.open('test.htm')
}else{
window.opener.location.hre f='test.ht m'
}
...and it doesn't work.
Anyone any ideas?
There is a link on Page B that needs to check whether Page A still exists. If it does it needs to run...
window.opener.location.hre
If the opener page doesn't exist then I need to run...
window.open('test.htm');
How can I detect whether the opener is still there.
I've tried...
if(!window.opener){
window.open('test.htm')
}else{
window.opener.location.hre
}
...and it doesn't work.
Anyone any ideas?
ASKER
Tried it....got a really wierd error message.
'The callee (server [not server application]) is not available and has disappeared; all connections are invalid. The call did not execute'
Any ideas?
'The callee (server [not server application]) is not available and has disappeared; all connections are invalid. The call did not execute'
Any ideas?
Strange.........could you paste all of the code you used?
Ant
Ant
What browser are you using?
Ant
Ant
Use this instead:
if( window.opener == null || window.opener.closed ){
alert("window is not open")
}
else{
alert("window is open")
}
And that won't make any difference - all you have done is reversed the logic of the if statement........
:o\
Ant
:o\
Ant
ASKER
no problem....here's the code
function goAdvert(id){
if(id==1){
if(!window.parent.opener.c losed && window.parent.opener != null){
window.parent.opener.locat ion.href = '../solutions/sol_display. asp?Soluti onID=5'
}else{
window.open('../solutions/ sol_displa y.asp?Solu tionID=5', 'CRM')
}
}
}
The page I'm using to call the function is in a frameset, hence window.parent
The code works fine if the opener is open, just not when it's closed.
I'm using IE5 but it needs to work in Netscape as well if possible.
Thanks
function goAdvert(id){
if(id==1){
if(!window.parent.opener.c
window.parent.opener.locat
}else{
window.open('../solutions/
}
}
}
The page I'm using to call the function is in a frameset, hence window.parent
The code works fine if the opener is open, just not when it's closed.
I'm using IE5 but it needs to work in Netscape as well if possible.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi BNBJ,
Have you tried my code. It should work.
Have you tried my code. It should work.
Yes it should because it is the same as my code, but with the logic reversed!!!!!!!
It is offering nothing more than what my code offers............
Ant
It is offering nothing more than what my code offers............
Ant
Well there we go you see - you are using frames. Try this instead:
function goAdvert(id){
if(id==1){
if(!top.opener.closed && top.opener != null){
top.opener.location.href = '../solutions/sol_display. asp?Soluti onID=5'
}else{
window.open('../solutions/ sol_displa y.asp?Solu tionID=5', 'CRM')
}
}
}
I'm assuming that the "child" window has frames in it....
Ant
function goAdvert(id){
if(id==1){
if(!top.opener.closed && top.opener != null){
top.opener.location.href = '../solutions/sol_display.
}else{
window.open('../solutions/
}
}
}
I'm assuming that the "child" window has frames in it....
Ant
The reason your code does not work is if window.opener == null, window.opener.closed will fail.
In my code window.opener == null will shortcut.
In my code window.opener == null will shortcut.
BNJB.
this code will automatically do the detection for you... try it, it works!
open the pageA.html... click the link to pop the pageB.html... there's a link in the pageB.html which opens the test.html in replacement for pageA.html... if pageA is closed, it creates another window... ;)
pageA.html
------------
<html>
<head>
<script language="Javascript">
window.name='pageA';
function poppageB() {
window.open('pageB.html',' ',config=' width=300, height=300 ');
}
</script>
</head>
<body>
<a href="#" onClick="poppageB();">Open Page B</a>
</body>
</html>
pageB.html
------------
<html>
<head>
<script language="Javascript">
window.name='pageB';
</script>
</head>
<body>
<a href="test.html" target="pageA">Open Test Page</a>
</body>
</html>
test.html
------------
<html>
<head>
<script language="Javascript">
window.name='test';
</script>
</head>
<body>
THE TEST PAGE
</body>
</html>
this code will automatically do the detection for you... try it, it works!
open the pageA.html... click the link to pop the pageB.html... there's a link in the pageB.html which opens the test.html in replacement for pageA.html... if pageA is closed, it creates another window... ;)
pageA.html
------------
<html>
<head>
<script language="Javascript">
window.name='pageA';
function poppageB() {
window.open('pageB.html','
}
</script>
</head>
<body>
<a href="#" onClick="poppageB();">Open
</body>
</html>
pageB.html
------------
<html>
<head>
<script language="Javascript">
window.name='pageB';
</script>
</head>
<body>
<a href="test.html" target="pageA">Open Test Page</a>
</body>
</html>
test.html
------------
<html>
<head>
<script language="Javascript">
window.name='test';
</script>
</head>
<body>
THE TEST PAGE
</body>
</html>
ASKER
ZhongYu,
Ant is right....your page is exactly the same as his with the logig reversed.....so it doesn't work.
pagemastah,
That works a treat....you can have the points. I didn't think about working it that way round. Simple and effective!
Ant,
Thanks for your comments anyway.
Laters ;-)
Ant is right....your page is exactly the same as his with the logig reversed.....so it doesn't work.
pagemastah,
That works a treat....you can have the points. I didn't think about working it that way round. Simple and effective!
Ant,
Thanks for your comments anyway.
Laters ;-)
ASKER
Thanks a lot...
does it work?
ASKER
yep!
welcome! anytime ; )
It works with me.
ASKER
The question is closed....thanks everyone.
if(!window.opener.closed && window.opener != null){
//window is open
}
else{
// window is not open
}
:o)
Ant