1

Suppose parent window has abc.xyz.com url and, I am opening a child window using: window.top.open

I am getting parent window object in child window using window.opener and polling the parent window url using window.opener.location.href.

Now, if the user click on a link in the parent window, which navigates to def.xyz.com then the window.opener.location.href is giving 'Permission Denied' and window.opener.closed is returning true. (in child script)

I need to change my child window if the parent window is not inside xyz.com

How do I know that the parent is navigated to xyz.com or some other domain?

Samir Lakhani
  • 485
  • 6
  • 14

2 Answers2

0

You can add some javascript to the parent window that modifies the child when it's URL changes. Using the window.onunload event would do the job:

window.onunload=function(){
    childWindow.location.href = 'parentURLChanged.html';
};

Instead of changing the location completely you could also only add a hash to the URL so It would change from child.html to child.html#parentHasChanged.
If you want more complete communication between these two windows I suggest you use the jQuery postMessage Plugin. It allows you to send and receive messages between two Windows or Frames and also works cross-domain.

ferdynator
  • 6,245
  • 3
  • 27
  • 56
0

Something like this:

query = window.parent.location.search.substring(1)

referenced from HERE. This one can also help.

Community
  • 1
  • 1
Gurminder Singh
  • 1,755
  • 16
  • 19