Languages :: DHTML, JScript :: quelle est le meilleur choix pour des liens HTML ? href="#" ? scroll ? best choice for links ? |
|||
| By: Bernard |
Date: 16/04/2006 09:35:09 |
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 | 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 |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








