471,616 Members | 1,076 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

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 1274
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
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.