visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: DHTML, JScript :: quelle est le meilleur choix pour des liens HTML ? href="#" ? scroll ? best choice for links ?


By: Bernard France  Date: 16/04/2006 09:35:09  English French  Points: 20 Status: Answered
Quality : Excellent
Hello, I see it as common habit to have links coded like :

<a href="#" onclick="my_function(this);">Click to do something</a>



Those links call Javascript when clicked. The use of the href="#" is to prevent navigating away from the page. However, it can cause the display to jerk around as the page auto-scrolls. This is pretty annoying for the user.

Is there a better solution ?
By: VGR Date: 16/04/2006 09:41:10 English French  Type : Answer
The problem is not the form of the href, but the OnClick event handling it. If your my_function() does NOT return false, then the link will be followed afterwards and you will experience those problems.
You may also add "return false;" in the href= value if you prefer.

Also, (if you don't put "return false;" in the href= or function return value), your display does scroll ***to the top***, not because the named anchor is anywhere ('#' does not exist after all), but because "#" is equivalent to "top of the page". I would suggest putting a "#dummy" in stead.

So, in short :
1) add the "return false();"
or
2) use "#dummyone" in stead of "#"

La meilleure solution est d'ajouter le "return false", oeuf corse :D

à+

Do register to be able to answer

EContact
browser fav
page generated in 337.841990 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page