Live data from Hacker News

Ask HN: the current state of the empty # in 'a href'

news.ycombinator.com

11–15 of 15 posts

Re: Ask HN: the current state of the empty # in 'a href'

#11
post #7
post #2

I use A without href only when I'm making an actual anchor A name. When I use href=#, I always have javascript onclick return false. This won't stop crawlers but it keeps the user's history and address bar clean.

what about href='' and in the jquery onclick function, return false at the end?

href='' will reload the current page in most browsers if the JS code hasn't loaded yet (waiting for $(function(){}) to fire) or has an error for some reason. href='#' will at least prevent that. Returning false form jQuery works.

Re: Ask HN: the current state of the empty # in 'a href'

#13
post #2

I use A without href only when I'm making an actual anchor A name. When I use href=#, I always have javascript onclick return false. This won't stop crawlers but it keeps the user's history and address bar clean.

Adding a no follow on the link would stop the crawlers actually. Your current approach with return false and a no follow is the approach I most commonly use. The full result looking like:

    

Re: Ask HN: the current state of the empty # in 'a href'

#14

I've always been a fan of oi! It'll look like a link (unlike leaving the href empty), and wont ever perform wacky page scrolling tricks or mess up your URL bar. That's been my signature since 1997. Don't see any reason to change it...

Here's a shorter version:

    

Re: Ask HN: the current state of the empty # in 'a href'

#15
If you want to retain IE6 compatibility (usually a must for government related sites!), I've found this technique is pretty solid for cross browser platform compatibility (IE6-9, FF, Chrome, Safari):

My link

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).

Post reply on HN