For a good separation of concerns, your best bet is to use attachEvent (IE) or addEventListener (standard) (or a toolkit that hides that from you, like Prototype, jQuery, MooTools, YUI, Glow, etc.) and then cancel the event from within JavaScript. Assuming this link:
<a href='foo' id='mylink'>Link text</a>
...here's an example using Prototype:
// Hook up your handler on page load
document.observe("dom:loaded", function() {
// Look up the link, apply your handler
$('mylink').observe('click', yourHandler);
});
// Your handler:
function yourHandler(event) {
// Prevent the default action
event.stop();
// ...your code here...
}
You don't have to assign the link an ID, there are lots of ways to find DOM elements other than IDs, but it makes a handy example.
jQuery, et. al., will have their own versions of event.stop(), but it comes down to cancelling the event.