How to call parent's parent javascript function from child window.
Example- Parent 1 has javascript function abc() Now how to call Parent1 Javascript function in Child window from Parent 2 which is initially trigged from Parent 1 Window. I tried window.parent.parent. Still no luck.
Thanks in advance
To call a parent's function from a child component, pass the function reference to the child component as a prop. Then you can call that parent's function from the child component like props. parentMethodName(). In the example code, we create a parent component named Parent.
Inside the SetName JavaScript function, the reference of the parent window txtName TextBox is obtained from window. opener instance using document. getElementById method of JavaScript. Finally, the DropDownList selected value is set into the TextBox value property.
This method safely enables cross-origin communication. And if you have access to parent page code then any parent method can be called as well as any data can be passed directly from Iframe.
Not sure what you mean with a child window. But I guess window.opener
might be what you are looking for.
// Call abc in the window that opened the current window
window.opener.abc();
Update
Haven't tried it, but since window.opener
is a reference to the window that opened the current window, then I guess you should be able to call the opener
property on that reference, to get a reference to the its parent as well:
window.opener.opener.abc();
If you want to reach the topmost window (the root window, or what you would call it), then you can use window.top
instead:
window.top.abc();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With