jkesce
asked on
window.opener.name - access denied
Good Morning!
I have read through every answer to any question related to window.opener and cannot find a solution to my problem.
I have a main window that opens a popup help window. One of the links in the popup help menu is supposed to load a url into the main window and then close the popup window.
The issue is this - if the main window if closed I need to open a new window with the url specified. If the main window is open everything works just fine. If the main window is closed and I try to access any property of window.opener I get an Access Denied error. The window.opener returns an object reference even if the opener has been closed. If the opener is open I can access it fine and even check the name of the window.
window.opener.closed - always returns false as others have mentioned.
Thanks for the help.
Jeannette
I have read through every answer to any question related to window.opener and cannot find a solution to my problem.
I have a main window that opens a popup help window. One of the links in the popup help menu is supposed to load a url into the main window and then close the popup window.
The issue is this - if the main window if closed I need to open a new window with the url specified. If the main window is open everything works just fine. If the main window is closed and I try to access any property of window.opener I get an Access Denied error. The window.opener returns an object reference even if the opener has been closed. If the opener is open I can access it fine and even check the name of the window.
window.opener.closed - always returns false as others have mentioned.
Thanks for the help.
Jeannette
ASKER
Just to clarify - I need something IE 5 and Netscape 4.5 compatible.
Consider this:
Window A opens Window B onclick of a button with javascript:window.open (blah blah)
On Window B there is a link. On click of the link I need to check the status of the opener. In this case the below function would need to be in my code for Window B. This is what does not work. I can never get a value of true from the first statement if the code is in Window B.
function OpenInParent()
{
if(window.opener.closed == true)
open("test.html", "main");
else
window.opener.location.rep lace("test .html");
}
Consider this:
Window A opens Window B onclick of a button with javascript:window.open (blah blah)
On Window B there is a link. On click of the link I need to check the status of the opener. In this case the below function would need to be in my code for Window B. This is what does not work. I can never get a value of true from the first statement if the code is in Window B.
function OpenInParent()
{
if(window.opener.closed == true)
open("test.html", "main");
else
window.opener.location.rep
}
ASKER
Just to clarify - I need something IE 5 and Netscape 4.5 compatible.
Consider this:
Window A opens Window B onclick of a button with javascript:window.open (blah blah)
On Window B there is a link. On click of the link I need to check the status of the opener. In this case the below function would need to be in my code for Window B. This is what does not work. I can never get a value of true from the first statement if the code is in Window B.
function OpenInParent()
{
if(window.opener.closed == true)
open("test.html", "main");
else
window.opener.location.rep lace("test .html");
}
Consider this:
Window A opens Window B onclick of a button with javascript:window.open (blah blah)
On Window B there is a link. On click of the link I need to check the status of the opener. In this case the below function would need to be in my code for Window B. This is what does not work. I can never get a value of true from the first statement if the code is in Window B.
function OpenInParent()
{
if(window.opener.closed == true)
open("test.html", "main");
else
window.opener.location.rep
}
ASKER
I was able to solve this problem with the following code:
function OpenWindow(strPage){
if(typeof(top.opener.docum ent) == "object") {
top.opener.location.href=s trPage;
}
else{
window.open (strPage);
}
top.close();
}
If the main window is no longer open top.opener still returns an object, but an attempt to access any of the properties results in an Access Denied error. The solution is to check if the typeof function returns "object" or "unknown". If this value is "unknown" the opener has been closed.
I will request this question be deleted.
Jeannette
function OpenWindow(strPage){
if(typeof(top.opener.docum
top.opener.location.href=s
}
else{
window.open (strPage);
}
top.close();
}
If the main window is no longer open top.opener still returns an object, but an attempt to access any of the properties results in an Access Denied error. The solution is to check if the typeof function returns "object" or "unknown". If this value is "unknown" the opener has been closed.
I will request this question be deleted.
Jeannette
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
glad you got a solution. for info, the closed property should work:
function OpenWindow(strPage){
if (!top.opener.closed) {
top.opener.location.href=s trPage;
}
else{
window.open (strPage);
}
top.close();
}
function OpenWindow(strPage){
if (!top.opener.closed) {
top.opener.location.href=s
}
else{
window.open (strPage);
}
top.close();
}
<html>
<body>
<a href="javascript:OpenWindo
<a href="javascript:OpenInPar
<script>
function OpenWindow()
{
open("test.html","child");
}
function OpenInParent()
{
if(window.opener.closed == true)
open("test.html", "main");
else
window.opener.location.rep
}
</script>
</body>
</html>