window.opener.name - access denied

jkesce
jkesce used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
The following works for me - I'm in win2K, IE6

<html>
<body>
<a href="javascript:OpenWindow()">Open a new window</a><br>
<a href="javascript:OpenInParent()">Open a page in the main wnd</a>

<script>
function OpenWindow()
{
     open("test.html","child");
}

function OpenInParent()
{
     if(window.opener.closed == true)
          open("test.html", "main");          
     else
          window.opener.location.replace("test.html");
}
</script>
</body>
</html>

Author

Commented:
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.replace("test.html");
}


Author

Commented:
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.replace("test.html");
}


Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I was able to solve this problem with the following code:

function OpenWindow(strPage){
     if(typeof(top.opener.document) == "object") {
          top.opener.location.href=strPage;    
     }
        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
From: jkesce  Date: 11/26/2002 10:30AM PST  
I was able to solve this problem with the following code:

function OpenWindow(strPage){
    if(typeof(top.opener.document) == "object") {
         top.opener.location.href=strPage;    
    }
       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  
ahosangFinance Systems Developer

Commented:
glad you got a solution. for info, the closed property should work:
function OpenWindow(strPage){
    if (!top.opener.closed) {
         top.opener.location.href=strPage;    
    }
       else{
         window.open (strPage);
    }          
    top.close();
}

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial