473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1302
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: rvdw | last post by:
Hi All, I've a serious problem with executing stored procedures (SQL2000) from an Access db (version 97). After executing a stored procedure , msaccess hangs. The whole call to the procedure is...
0
by: Nick Coghlan | last post by:
Anyone playing with the CPython interpreter's new command line switch might have noticed that it only works with top-level modules (i.e. scripts that are directly on sys.path). If the script is...
15
by: Nick Coghlan | last post by:
Python 2.4's -m command line switch only works for modules directly on sys.path. Trying to use it with modules inside packages will fail with a "Module not found" error. This PEP aims to fix that...
4
by: chris.dunigan | last post by:
I'm looking for an example of how to execute an existing DTS­ package from an ASP (VB)script and would appreciate any and all response. ­I don't even know if it's possible Thanks - Chuck...
1
by: rvdw | last post by:
Hi All, I've a serious problem with executing stored procedures (SQL2000) from an Access db (version 97). After executing a stored procedure , msaccess hangs. The whole call to the procedure is...
2
by: Tony Liu | last post by:
Hi, I want to get the name of the calling function of an executing function, I use the StackTrace class to do this and it seems working. However, does anyone think that there any side effect...
0
by: Rahul Chatterjee | last post by:
Hello All I have designed a dotnet application using VB which basically takes a selection and passes value to a crystal report which in turn passes the value to a Stored procedure. After the...
7
by: tshad | last post by:
I thought I understood how the SaveViewState is working and was trying to use this (as per some code I found) to detect refreshes. It seemed to be working but I found that the SaveViewState was...
5
by: reycri | last post by:
Hi, I need to be able to do this: var func = new Function("var me = <selfRef>; alert(me.params);"); func.params = "This is a test parameter"; window.setTimeout(func, 500); Basically, I...
2
by: Swan | last post by:
How can I restrict alt+tab and start menu from keyboard while program executing(VB)?I am posting what I tried-- form.frm Option Explicit Private Sub Form_Load() HookKeyboard End Sub...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.