executing a function from string text

Discussion in 'Javascript' started by Merrill Higginson, Aug 12, 2004.

  1. 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
    Merrill Higginson, Aug 12, 2004
    #1
    1. Advertising

  2. 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
    Thomas 'PointedEars' Lahn, Aug 12, 2004
    #2
    1. Advertising

  3. Merrill Higginson

    Robert Guest

    (Merrill Higginson) wrote in message news:<>...

    > 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
    Robert, Aug 12, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul McGuire
    Replies:
    0
    Views:
    281
    Paul McGuire
    Dec 16, 2003
  2. =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    Replies:
    5
    Views:
    1,281
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    May 6, 2006
  3. Adam Knight

    Executing ASP Contained in a Text Stream.

    Adam Knight, Aug 3, 2003, in forum: ASP General
    Replies:
    1
    Views:
    94
  4. Replies:
    1
    Views:
    186
    Dr.Ruud
    Jul 29, 2006
  5. Mark
    Replies:
    17
    Views:
    222
    Mirco Wahab
    Mar 25, 2007
Loading...

Share This Page