views:

2085

answers:

3

I had two domains for ex. domain1 and domain2, I am opening domain2/index.aspx page as popup from domain1/default.aspx page. While closing domain2 page i need to reload the domain1 page, i had given the javascript code as "Opener.Location.Reload();". I am getting Permission denied javascript error. Any ideas about this issue.

+1  A: 

Certain properties and actions are specifically blocked in cross-domain scenarios. What you might be able to do is create a function on the parent that does the code you want, then call that function from the child.

Example:

// On the parent...
function DoTheRefresh()
{
    location.reload();
}

Then, on the child:

opener.DoTheRefresh();

I have done this in the past, so I don't know for sure if it's still an option. I hope it works out for you :)

Timothy Khouri
A: 

You can accomplish this by putting code in the parent window to detect when the child window has closed.

var win2;

function openWindow()
{
  win2 = window.open('http://...','childwindow',...);
  checkChild();    
}

function checkChild() {
  if (win2.closed) {
    window.location.reload(true);
  } else setTimeout("checkChild()",1);
}
Kosta
A: 

I found that setting a parentUrl variable in the popup window (gotten from a query string) and then using :

window.opener.location.href = parentUrl;

works.

I don't know why, I think it's magic, but it works (tested on IE, chrome and Firefox). You cannot read the value of window.opener.location.href, but you can set it to whatever url you want. I use this oddity to do the refresh.

Hope it helps

lau