how to prevent scroll up on chrome for a href="#"
So basically I have
<a href="#" onClick="return false">Link</a>
And return false is there so that it wont' scroll up when you click on it. This works in IE and Firefox, but in chrome it still scrolls up nonetheless...
How do you prevent this from happening in Chrome?
Thanks 开发者_运维问答in advance
There is no spoon
-The Matrix
Use: <a href="javascript:;">Link</a>
<a href="#" onclick="e.preventDefault(); return false;">Link</a>
Don't have a link that points to the top of the page (which is what the URI # means), build on stuff that works.
That said, the return false
should prevent the link from being followed, so long as JavaScript is active and error free. Since a link to the top of the page is undesired and a script that does nothing is pretty useless — I'd guess you have some other JS before the return statement that is erroring so the return is never reached.
you probably use href="#" to enable onclick functionality on <a> tag. you can disable the href with href="void(0)" and you won't get the side effect of scroll to top on chrome
精彩评论