views:

363

answers:

2

I think my title was informative enough. :)

I close the child window like this:

self.close();

Just before this, I want the parent window to know that the child has closed. I am making use of this:

window.opener.startLoad();

The above will run a function that is on the parent window that I need it to run upon the child window closing.

However, this has led to me getting an error:

Permission denied to get property Window.startLoad
window.opener.startLoad();

Even if I could fix this error, I was told it may be due to JavaScript file being in a different folder and therefore seen as a different domain. Will this work across all browsers? If not, is there a safer solution that is efficient and compatible across all the browsers?

Thank you for any help.

+1  A: 

This should work as long as the popup is from the same domain as the parent, otherwise due to security restrictions it will never work. Folder is irrelevant.

if (window.opener && window.opener.startLoad)
{
    window.opener.startLoad();
}
cdm9002
I still the same error. Why do you think placing it in a conditional would make a difference? I am not trying to question you, I am just trying to understand your logic. :)
Abs
I was more just giving code that I use which checks for a valid parent and the function. This works unless they are not in the same domain - in which case you get that error. Are yours?
cdm9002
My scripts are on the same domain and even the same folder. However, the child window when it first opens it goes to a different site and then gets redirected back to my site and then closes. Then it tries to fire a function from parent window which seems to fail.
Abs
A: 

With some of my Javascript test pages, when using it in IE, it gives an error locally, but uploading the file to the the Internet and opening it from there works. Maybe you have some strange security setting that's not allowing you to make requests on the same "domain" while running from a local file. Try putting the pages on a web host and see if that works.

thezachperson31
I have just checked on another machine with a different browser and I get the same error. The child window is redirected from another site to my site where the JS script resides, would this redirection cause a problem?
Abs
Yes, fails because of cross-site scripting security. You must open the child window from your own domain.
cdm9002
I do open from own domain, its just that I redirect to a different site and then back again. But ultimately i open the child window.
Abs
Ok, sorry, I was generalizing, I still think you are falling foul of the security issue. If you emulate the other site by keeping it within your domain, does it then work?
cdm9002
Ok, I have simulated that and it works if I do not redirect elsewhere. Damn it, Javascript and its over restrictions! What can I do to trigger the event on close? I think this requires a new question.
Abs