Link to run script and link to page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl Gilbert

    Link to run script and link to page

    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="javascrip t:GetCookie('li nkcookie')">add 1 to linkcookie</A>

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

    Many thanks, Carl Gilbert
  • kaeli

    #2
    Re: Link to run script and link to page

    In article <66d5a399.04011 31314.715559b1@ posting.google. com>,
    mr_carl_gilbert @hotmail.com enlightened us with...[color=blue]
    > Hi
    >
    > How can I use a link to both run a peice of script and link to another page?[/color]

    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.

    [color=blue]
    >
    > <A href="javascrip t:GetCookie('li nkcookie')">add 1 to linkcookie</A>[/color]

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


    --
    --
    ~kaeli~
    Why do people who know the least know it the loudest?



    Comment

    • Michael Winter

      #3
      Re: Link to run script and link to page

      On 13 Jan 2004 13:14:55 -0800, Carl Gilbert <mr_carl_gilber t@hotmail.com>
      wrote:
      [color=blue]
      > 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="javascrip t:GetCookie('li nkcookie')">add 1 to linkcookie</A>[/color]

      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.h tml" onclick="GetCoo kie('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="someFu nction(); 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
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • Lee

        #4
        Re: Link to run script and link to page

        Carl Gilbert said:[color=blue]
        >
        >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="javascrip t:GetCookie('li nkcookie')">add 1 to linkcookie</A>[/color]

        <a href="http://www.myotherpage .com"
        onclick="GetCoo kie('linkcookie ');return true">

        Comment

        Working...