Hash/Pound/# characters in links, alternative links that don’t change the URL in the users broswer !

An interesting alternative to a link with a hash (alternative zu link mit hash) such as href="#thisgoesnowhere", which causes the insertion of the “#” character and any following characters to the end of the URL, is to use a null javascript link target.


In this case, whether the link is clicked or the onclick function errors or returns a non false value doesn’t matter, the browser stays on the page and the URL doesn’t needlessly changed.

Example 1 – null javascript link: Cannot actually embed ablink here as wordpresss filtering removes the “javascript” piece from “javascript:void(0)”. But on your own site, without filtering of the html, it’s pretty handy, esp for some dynamic sites with background actions, animations, etc.

Example 2 – hash link: Note the current URI, now try this link. The URI has changed to have “#thisGoesNowhere” appended to the end, right ? Not very nice, and if your URI is shared or bookmarked, this may have unintended consequences.

Arguably we should (?) be using the button or some other tag in this case, but if we want to stick with the anchor tag (as I do) then this approach can work well.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s