Wednesday, October 01, 2008

Javascript - Access Denied When Calling Window Opener

We usually use the "open" method in the window object to open a new window in Javascript. However, sometimes you need to change some values in the parent window depending on the changes of the new window elements values or you may need to call a method in the parent window from the child one. To do so, you can use the "opener" property in the window object to access the parent page elements. The following Javascript statement access an input element in the parent window with "txtEmail" ID and update its value:

window.opener.document.getElementById("txtEmail").value = "";
You can even call a method direct in the parent window from the new opened one:
However, you may get "Access Denied" or "Permission Denied" message when trying to access the "opener" property in the popup window. This usually because you call the with the full path of the pop window:'');
To resolve this issue, use the relative path of the popup page instead of the full path when opening it and you will be able to safely access the opener property of the window.'accounts/register_popup.aspx');


Anonymous said...

But In case your popup is from another server you have to specify full path. In that case how can we avoid this error?

Mohammed Nour said...

You may open another window in your application which then redirects either from server side or from the javascript to the external domain URL.