Monday, September 28, 2009

Null Links Best Practice

There have been instance were you want something to look like a link, but do something else when someone clicks is.

There are some various solutions out there, but here's the one I recommend.

Format your link like this
<a href="requirements.asp" onClick="javascript:YourJavascriptStuff;return false;">
Here's how this works: Make a page called requirements.asp, and on that page you list the minimum user requirements required for users to use your site. Obviously JavaScript is one of them.

When a user clicks the link, if they don't have a Javascript enabled browser, or have Javascript turned off, it will send them to the requirements page.

If they do have Javascript enabled, the 'return false' interrupts the HTTP call make by the href and executes the Javascript instead.

So it looks like a link, and will act like a link if there's no Javascript. If there is, the Javascript call will execute.

No comments: