Ask HN: the current state of the empty # in 'a href'
It used to be and may still be very well be today the 'good practice' to always have a # at least in the HREF. Empty or no HREF could cause issues with some browsers I was told.
Today it raises other problems. Those # litter web applications making link sharing duplicates in news site (ie. .com/# is different than .com/ but shouldn't), it also makes statistics skewed in some stats services.
I personally hate to see those empty domain.com/#
Note I have nothing against anchors actually being used as anchors, ie domain.com/#somesection. That's not what I'm referring to.
It also annoys me off to have those littering # in my browser history (ie. when you type in the url bar).
Is there an alternative? Using <button> everywhere can also cause issues in some browsers I read, with some browser using the content of the button tag as labels while some others use the value attribute.
Is using A with no href still SIN today?
And don't tell me about HTML5. If it's not everywhere it's not on my cards.
Thanks.
That's been my signature since 1997. Don't see any reason to change it...
(preventDefault is preferable though.)
<a href="#" onclick="DoSomething(); return false;">My link</a>
1) When you hover over the link, a 'hand' cursor appears for every browser (due to the #)
2) IE6 (in particular) won't barf at running your javascript code found in the onclick handler.
If your href tag contained "javascript:void(0)" instead of "#"; your code may not be run under IE6.
3) Because you 'return false' on the onclick, all browsers still avoid leaving the customers web browser with an unnecessary # in the top of the Url bar (as the click is effectively cancelled).
E.g.