Set a callback function to a new window in javascript
Posted
by SztupY
on Stack Overflow
See other posts from Stack Overflow
or by SztupY
Published on 2010-05-09T12:01:10Z
Indexed on
2010/05/09
12:08 UTC
Read the original article
Hit count: 275
Is there an easy way to set a "callback" function to a new window that is opened in javascript? I'd like to run a function of the parent from the new window, but I want the parent to be able to set the name of this particular function (so it shouldn't be hardcoded in the new windows page).
For example in the parent I have:
function DoSomething { alert('Something'); }
...
<input type="button" onClick="OpenNewWindow(linktonewwindow,DoSomething);" />
And in the child window I want to:
<input type="button" onClick="RunCallbackFunction();" />
The question is how to create this OpenNewWindow
and RunCallbackFunction
functions. I though about sending the function's name as a query parameter to the new window (where the server side script generates the appropriate function calls in the generated child's HTML), which works, but I was thinking whether there is another, or better way to accomplish this, maybe something that doesn't even require server side tinkering.
Pure javascript, server side solutions and jQuery (or other frameworks) are all welcomed.
© Stack Overflow or respective owner