Try this:
<a href="#" onclick="func(); return false;">link</a>
Notice that the onclick
parameter returns false
. Returning false cancels the default browser behavior. In the case of an anchor tag, the default browser behavior is to jump to the #
anchor (aka the top of the page).
With this same trick you can also make image un-draggable and ensure that links don't steal the user's focus:
<img src="coolios.jpg" onmousedown="return false" /> <!-- un-draggable image -->
<a href="stuff.html" onmousedown="return false">link that doesn't steal focus</a>
Maybe this will do the trick?
<a href="javascript: return false;" onclick="blahblah">
I always use
<a href="javascript:void(0)" onclick="blahblah">
Returning false in 'onclick' prevents page jump
<a href="#" onclick="someFunction(); return false;">blah</a>