Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts

    JavaScript link issues

    I recently wrote a page link to take user's to the top of the page using the following:
    Code:
    <a href="#" onClick="scroll(0, 0);">Top</a>
    I put the # sign in the href attribute so that the link would look like a standard clickable link.

    Are there any known issues with doing this?

    Is there a better way to do it, maybe using CSS?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Is the user handicapped and unable to hit their Home key?
    Just curious.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    The link sits at the end of a row of other page related functions for convenience sake. Less movement required to move the mouse a couple hundred pixels and click than to move the hand off the mouse to press the Home key.

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Gotcha.
    I'm such a key pressing chick.

    Anyway, to improve your code, add return false; otherwise the page hiccups.
    <a href="#" onClick="scroll(0, 0);return false;">Top</a>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by nikkiH
    Gotcha.
    I'm such a key pressing chick.
    Ever read "Don't Make Me Think"? Very good book that focuses on web design and intuitiveness. Most of my customer's already have too much on their minds each day. The more obvious I can make any feature the better.

    Anyway, to improve your code, add return false; otherwise the page hiccups.
    <a href="#" onClick="scroll(0, 0);return false;">Top</a>
    Ahh yes, the browser was definately having hiccups.

    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •