Link to run script and link to page

C

Carl Gilbert

Hi

How can I use a link to both run a peice of script and link to another page?

So far I have the following:
 
K

kaeli

Hi

How can I use a link to both run a peice of script and link to another page?

Assuming DOM browsers (easier that way). If you need to support older
browsers such as NN4, do not do this. :)
Older browsers do not support onClick of A.

<A href="javascript:GetCookie('linkcookie')">add 1 to linkcookie</A>

<a href="link.html" onClick="GetCookie('linkcookie');">add</a>


--
 
M

Michael Winter

How can I use a link to both run a peice of script and link to another
page?

So far I have the following:

<A href="javascript:GetCookie('linkcookie')">add 1 to linkcookie</A>

You shouldn't use javascript: URIs. They can cause a lot of problems.
Instead, use the onclick intrinsic event. This has the added advantage, in
your case, that it frees up the href attribute and allows it to be used
properly. For example,

<A href="newPage.html" onclick="GetCookie('linkcookie')">Add 1 to
linkcookie</A>

For future reference: when clicked, the above link will first execute the
JavaScript function in the onclick event attribute, then navigate to
newPage.html. If you want to only execute the onclick event code, place a
'return false' statement after the code. For example,

<A href="somePage.html" onclick="someFunction(); return false">Some
link</A>

The primary purpose of a link like the one above is to provide
functionality for users who might not have JavaScript enabled (a sizable
portion of WWW users). With JavaScript enabled, someFunction() will be
executed. Without it, the user will be taken to somePage.html.

Hope I explained that adequately,

Mike
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top