I have a popup system in my project. With a name, for example 'addnews', it knows which popup content to add and which script is necessary to handle the form. Up until now after completion I always did the same thing. Now, in some cases, I want to do something different.
Now I want to add a JavaScript function with that same name, like previous example 'addnews()', and check if that function exist. If it does run it, else do the standard things. (1)
Also executing a function with that name as variable doesn't seem to work. (2)
var functionName = 'addnews';
if (typeof functionName == 'function') { // (1) typeof functionName = string
window[functionName](); // (2) this doesn't work for me
} else {
// Do something standard
}
function addnews() {
// Do something special
}