469,290 Members | 1,882 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

executing a function from string text

I have an application that navigates through the links in a document,
most of which are "javascript:doThisFunction(args)" type of links.
Using DOM navigation I can find the reference to the javascript
function and store it as a String variable, but is there a way to
execute the function? Currently the only way I know how to do it is
in a series of if/else statements as in:

if (link=="doThisFunction(args)")
doThisFunction(args);
else if (link=="doThatFunction(moreArgs)")
doThatFunction(moreArgs);
... etc.

is there a more elegant way to do this?

Merrill
Jul 23 '05 #1
2 1256
Merrill Higginson wrote:
I have an application that navigates through the links in a document,
most of which are "javascript:doThisFunction(args)" type of links.
<http://jibbering.com/faq/#FAQ4_24>
Using DOM navigation I can find the reference to the javascript
function and store it as a String variable, but is there a way to
execute the function?
You already "execute" the function as the expression within the
"javascript:" URI is evaluated.
Currently the only way I know how to do it is
in a series of if/else statements as in:

if (link=="doThisFunction(args)")
doThisFunction(args);
else if (link=="doThatFunction(moreArgs)")
doThatFunction(moreArgs);
.. etc.

is there a more elegant way to do this?


It is unclear what you intend to do. However, using event handler
attributes instead, as of DOM Level 0 (proprietary) you would be
able to call the event handler using its lowercased attribute name,
once you have a reference to the respective DOM element object.
HTH

PointedEars
Jul 23 '05 #2
bo******@hotmail.com (Merrill Higginson) wrote in message news:<8b*************************@posting.google.c om>...
if (link=="doThisFunction(args)")
doThisFunction(args);
else if (link=="doThatFunction(moreArgs)")
doThatFunction(moreArgs); is there a more elegant way to do this?

I am not sure I would call this elegant since most people refer to
eval as the evil eval function. Try:

eval(link);

Robert
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Nick Coghlan | last post: by
15 posts views Thread by Nick Coghlan | last post: by
reply views Thread by Rahul Chatterjee | last post: by
7 posts views Thread by tshad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.