stopping <a> from loading new page but still performing onclick action

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

    stopping <a> from loading new page but still performing onclick action

    hi all

    i want to use hyperlinks to 'load' content by changing the display of
    div tags. the problem i have is that unless i specify a href the anchor
    does not change the mouse pointer on hover even if display is set to
    block. it only look changes when there is a href there. but if i have a
    href there then when i click it will load the page, which i dont want.

    how can i get the anchor to look like a proper link where the users
    pointer changes on hover (in firefox) but a page does not get refreshed
    onclick only the onclick function gets loaded.

    regards

    marc

  • gbbulldog

    #2
    Re: stopping &lt;a&gt; from loading new page but still performing onclick action

    monomaniac21 wrote:
    hi all
    >
    i want to use hyperlinks to 'load' content by changing the display of
    div tags. the problem i have is that unless i specify a href the anchor
    does not change the mouse pointer on hover even if display is set to
    block. it only look changes when there is a href there. but if i have a
    href there then when i click it will load the page, which i dont want.
    >
    how can i get the anchor to look like a proper link where the users
    pointer changes on hover (in firefox) but a page does not get refreshed
    onclick only the onclick function gets loaded.
    >
    regards
    >
    marc
    Place a single hash into the href property of the anchor tag.
    (href="#").

    Comment

    • Alvaro G. Vicario

      #3
      Re: stopping &lt;a&gt; from loading new page but still performing onclick action

      *** monomaniac21 escribió/wrote (4 Sep 2006 08:21:09 -0700):
      i want to use hyperlinks to 'load' content by changing the display of
      div tags. the problem i have is that unless i specify a href the anchor
      does not change the mouse pointer on hover even if display is set to
      block.
      Not even if you specify a cursor in your style sheet?

      cursor: pointer;

      it only look changes when there is a href there. but if i have a
      href there then when i click it will load the page, which i dont want.
      It won't load anything if you cancel the action:

      <a href="http://www.google.com" onclick="return false">Google</a>

      or if you don't set an HTTP link:

      <a href="javascrip t:alert('Hello, World!')">Googl e</a>




      --
      -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
      ++ Mi sitio sobre programación web: http://bits.demogracia.com
      +- Mi web de humor con rayos UVA: http://www.demogracia.com
      --

      Comment

      • Nick D

        #4
        Re: stopping &lt;a&gt; from loading new page but still performing onclick action

        Sometimes this could cause a problem by jumping to the top of the page.
        Another way to do this without making the page jump would be to put (<a
        href="javascrip t:void(0)" onclick="SomeFu nction()">)

        gbbulldog wrote:
        monomaniac21 wrote:
        hi all

        i want to use hyperlinks to 'load' content by changing the display of
        div tags. the problem i have is that unless i specify a href the anchor
        does not change the mouse pointer on hover even if display is set to
        block. it only look changes when there is a href there. but if i have a
        href there then when i click it will load the page, which i dont want.

        how can i get the anchor to look like a proper link where the users
        pointer changes on hover (in firefox) but a page does not get refreshed
        onclick only the onclick function gets loaded.

        regards

        marc
        >
        Place a single hash into the href property of the anchor tag.
        (href="#").

        Comment

        • Good Man

          #5
          Re: stopping &lt;a&gt; from loading new page but still performing onclick action

          "Nick D" <nick.denardis@ gmail.comwrote in
          news:1157393471 .762756.201500@ m79g2000cwm.goo glegroups.com:
          Sometimes this could cause a problem by jumping to the top of the
          page. Another way to do this without making the page jump would be to
          put (<a href="javascrip t:void(0)" onclick="SomeFu nction()">)
          i usually call:

          <a href="javascrip t://Click To Change Divs" onclick="change Div();">


          i believe my example is proper coding practice - any href="javascrip t:xxx"
          should be avoided at all costs.

          best,
          gm

          Comment

          • Nick D

            #6
            Re: stopping &lt;a&gt; from loading new page but still performing onclick action

            All of the examples in this thread are depreciated. None of them will
            degrade gracefully. You should ALWAYS use the (<a
            href="action_pa ge.html">Link</a>) Then attach an onload javascript
            function that will run through all link tags and add the proper onclick
            event and removing the traditional "href" properties. This way your
            script will ALWAYS work even if javascript is disabled.

            Reference: http://www.w3.org/TR/WCAG10-HTML-TECHS/


            Good Man wrote:
            "Nick D" <nick.denardis@ gmail.comwrote in
            news:1157393471 .762756.201500@ m79g2000cwm.goo glegroups.com:
            >
            Sometimes this could cause a problem by jumping to the top of the
            page. Another way to do this without making the page jump would be to
            put (<a href="javascrip t:void(0)" onclick="SomeFu nction()">)
            >
            i usually call:
            >
            <a href="javascrip t://Click To Change Divs" onclick="change Div();">
            >
            >
            i believe my example is proper coding practice - any href="javascrip t:xxx"
            should be avoided at all costs.
            >
            best,
            gm

            Comment

            • william.clarke

              #7
              Re: stopping &lt;a&gt; from loading new page but still performing onclick action

              Nick D wrote:
              All of the examples in this thread are depreciated. None of them will
              degrade gracefully. You should ALWAYS use the (<a
              href="action_pa ge.html">Link</a>) Then attach an onload javascript
              function that will run through all link tags and add the proper onclick
              event and removing the traditional "href" properties. This way your
              script will ALWAYS work even if javascript is disabled.
              >
              Reference: http://www.w3.org/TR/WCAG10-HTML-TECHS/
              Funny, not one of the examples in the Links section of that document
              showed anything that resembled the issue that is being discussed here.
              (ie. no examples of how the accessibility standard can be applied to
              <ajavascript. )
              >Then attach an onload javascript function that will run through all link tags and add the >proper onclick event and removing the traditional "href" properties.
              >This way your script will ALWAYS work even if javascript is disabled.
              How can that be true? If Javascript is disabled then Javascript is
              disabled, just adding "onload" Javascript won't get around that. Maybe
              I'm missing something there, but I always thought that if Javascript is
              disabled, then no Javascript at all would run. Can someone clarify this?

              Comment

              • Nick D

                #8
                Re: stopping &lt;a&gt; from loading new page but still performing onclick action

                Yes, If javascript is disabled there will be no change to the page and
                the original href="actionpag e.html" link will be executed. But if
                javascript is enabled then the onload will run thus removing all
                original conventional href locations and replacing them with javascript
                actions. Here is a more precise example you were probably looking for.
                For accessibility degradable javascript is the way to go.



                william.clarke wrote:
                Nick D wrote:
                All of the examples in this thread are depreciated. None of them will
                degrade gracefully. You should ALWAYS use the (<a
                href="action_pa ge.html">Link</a>) Then attach an onload javascript
                function that will run through all link tags and add the proper onclick
                event and removing the traditional "href" properties. This way your
                script will ALWAYS work even if javascript is disabled.

                Reference: http://www.w3.org/TR/WCAG10-HTML-TECHS/
                >
                Funny, not one of the examples in the Links section of that document
                showed anything that resembled the issue that is being discussed here.
                (ie. no examples of how the accessibility standard can be applied to
                <ajavascript. )
                >
                Then attach an onload javascript function that will run through all link tags and add the >proper onclick event and removing the traditional "href" properties.
                This way your script will ALWAYS work even if javascript is disabled.
                >
                How can that be true? If Javascript is disabled then Javascript is
                disabled, just adding "onload" Javascript won't get around that. Maybe
                I'm missing something there, but I always thought that if Javascript is
                disabled, then no Javascript at all would run. Can someone clarify this?

                Comment

                • william.clarke

                  #9
                  Re: stopping &lt;a&gt; from loading new page but still performing onclick action


                  Nick D wrote:
                  Yes, If javascript is disabled there will be no change to the page and
                  the original href="actionpag e.html" link will be executed. But if
                  javascript is enabled then the onload will run thus removing all
                  original conventional href locations and replacing them with javascript
                  actions. Here is a more precise example you were probably looking for.
                  For accessibility degradable javascript is the way to go.
                  >
                  http://particletree.com/features/the...gradable-ajax/
                  Thanks for clearing that one up, I understand what you meant now :)

                  Comment

                  • Noodle

                    #10
                    Re: stopping &lt;a&gt; from loading new page but still performing onclick action


                    Nick D wrote:
                    All of the examples in this thread are depreciated. None of them will
                    degrade gracefully. You should ALWAYS use the (<a
                    href="action_pa ge.html">Link</a>) Then attach an onload javascript
                    function that will run through all link tags and add the proper onclick
                    event and removing the traditional "href" properties. This way your
                    script will ALWAYS work even if javascript is disabled.
                    >
                    Reference: http://www.w3.org/TR/WCAG10-HTML-TECHS/
                    >
                    >
                    Good Man wrote:
                    "Nick D" <nick.denardis@ gmail.comwrote in
                    news:1157393471 .762756.201500@ m79g2000cwm.goo glegroups.com:
                    Sometimes this could cause a problem by jumping to the top of the
                    page. Another way to do this without making the page jump would be to
                    put (<a href="javascrip t:void(0)" onclick="SomeFu nction()">)
                    i usually call:

                    <a href="javascrip t://Click To Change Divs" onclick="change Div();">


                    i believe my example is proper coding practice - any href="javascrip t:xxx"
                    should be avoided at all costs.

                    best,
                    gm
                    A javascript that run's through and removes all the href's from anchor
                    tags onload seems a bit complex. Just add "return false" to the end of
                    the onclick call to stop the href from firing after the javascript has
                    executed. If javascript is diabled, the link will still work.

                    e.g.

                    <a href="http://www.somewhere.c om" onclick="alert( 'hello'); return
                    false;">click me</a>

                    Comment

                    Working...