I've had a wish for a long time now - to be able to trigger a function from within a popup window function (that is quite complicated itself).
I've tried running one function after another from the main form, but that doesn't work because it doesn't let the first one finish before it fires off the second one.
If you want to make it a common script library, you have to be able to pass in a variable as the function name. What if it's a function with arguments? Then you need to pass in the arguments.
Well, here is what I came up with and I am very please that it works. Here is the gist that will give you the syntax:
"
//set up the variables ... onClick event:
runFunction = "manyNames";
runFNArgs = "1";
ThisisMyfunction( runFunction, runFNArgs);
//run an add on function passed by a variable not a string
if (runFunction != null && runFunction != "" && (runFNArgs == null || runFNArgs == "")) {
window.opener[runFunction ]();
} else {
if (runFunction != null && runFunction != "" && runFNArgs != null && runFNArgs != ""){
window.opener[runFunction ](runFNArgs);
}
}
self.close();
}
"
So anyway, I did it and I am quite proud. The real secret is in the square brackets [].
No comments:
Post a Comment