How to call parent javascript function from child window

How to call parent javascript function from child window.

EXAMPLE- Parent 1 has the javascript function abc () Now how to call the Parent1 Javascript function in the Child window from parent 2, which is initially launched from the "Parent 1" window. I tried window.parent.parent. Not lucky yet.

Thank you in advance

+4
source share
1 answer

Not sure what you mean with the child window. But I think window.opener may be what you are looking for.

 // Call abc in the window that opened the current window window.opener.abc(); 

Update

I have not tried it, but since window.opener is a link to a window that opens the current window, I think you should be able to call the opener property in this link to get a link to its parent:

 window.opener.opener.abc(); 

If you want to get to the topmost window (the root window or what you would call it), you can use window.top instead:

 window.top.abc(); 
+5
source

Source: https://habr.com/ru/post/1436132/


All Articles