Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call parent's parent javascript function from child window

Tags:

javascript

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

like image 448
Beginner Avatar asked Sep 25 '12 11:09

Beginner


People also ask

How do you call a parent function from a child function?

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.

How do I pass a value from child window to parent window?

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.

Can Iframe call function in parent?

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.


1 Answers

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();
like image 98
Christofer Eliasson Avatar answered Nov 15 '22 08:11

Christofer Eliasson