Link to run script and link to page

Discussion in 'Javascript' started by Carl Gilbert, Jan 13, 2004.

  1. Carl Gilbert

    Carl Gilbert Guest

    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:

    -----------------------------------------------------------------------

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

    -----------------------------------------------------------------------

    Many thanks, Carl Gilbert
    Carl Gilbert, Jan 13, 2004
    #1
    1. Advertising

  2. Carl Gilbert

    Lee Guest

    Carl Gilbert said:
    >
    >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:
    >
    >-----------------------------------------------------------------------
    >
    ><A href="javascript:GetCookie('linkcookie')">add 1 to linkcookie</A>


    <a href="http://www.myotherpage.com"
    onclick="GetCookie('linkcookie');return true">
    Lee, Jan 13, 2004
    #2
    1. Advertising

  3. Carl Gilbert

    kaeli Guest

    In article <>,
    enlightened us with...
    > 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>


    --
    --
    ~kaeli~
    Why do people who know the least know it the loudest?
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    kaeli, Jan 13, 2004
    #3
  4. On 13 Jan 2004 13:14:55 -0800, Carl Gilbert <>
    wrote:

    > 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

    --
    Michael Winter
    d (replace ".invalid" with ".uk" to reply)
    Michael Winter, Jan 13, 2004
    #4
    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. Replies:
    5
    Views:
    472
  2. Replies:
    1
    Views:
    334
    Larry Bates
    Dec 14, 2006
  3. Replies:
    6
    Views:
    870
  4. sophie_newbie

    Error when python script run as cgi script

    sophie_newbie, Oct 21, 2007, in forum: Python
    Replies:
    3
    Views:
    597
    Dennis Lee Bieber
    Oct 22, 2007
  5. Replies:
    9
    Views:
    970
    Paddy O'Loughlin
    Feb 27, 2009
Loading...

Share This Page