Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i call a window child function in javascript?

I am calling the parent function like window.parent.functionname(); from the child page. How can i call the window.child.function() from the parent page to child page.

Any help is appreciated.

like image 283
Jonathan Avatar asked Dec 19 '12 13:12

Jonathan


People also ask

What is child window in JavaScript?

A window that opens inside a parent window is a child window. The action taken on the parent window reflects on the child window as well. For example, if you close the parent window, the child window closes too.

How do I listen to my child closing windows?

If you store a reference to the child window when you call window. open() , then you can poll using setInterval() to see whether the window is still open using the window. closed property. The example below checks twice per second.


2 Answers

Give your iFrame an id and try

document.getElementById("iFrameId").contentWindow.functionname()

This works even when you have multiple iFrames in the same page irrespective of their order.

like image 54
Bruno Avatar answered Nov 15 '22 21:11

Bruno


Do you have an iframe?

Do something like that:

window.frames[0].contentDocument.functionname();
like image 44
algorhythm Avatar answered Nov 15 '22 21:11

algorhythm