Forum Moderators: open
A big difference is that the pseudo-URL can only be used as the target of a link, while onclick can be used with almost any element, including block elements.
If you have a link, the only purpose of which is to fire a script, the outcome of using the pseudo-URL is little different than the onclick. Bear in mind, if you use the onclick on such a link you will need to set the href of the link to something benign, like href="#", otherwise strange things can happen if JavaScript is disabled.
A common and useful trick is to point the link to a fall-back URL for a page that displays if JS is disabled. The onclick action then returns "false" to cancel the link's activation, if the script runs successfully. Searching this forum you will be able to find many examples of this kind of usage.
onclick method is far better than the (deprecated) javascript: pseudo-URL, as the former allows you to have a fallback solution if the user has Javascript disabled. The very simplest example is with a link which opens a popup window - if you use onclick, you can offer the same page in a new window for users without Javascript: <a href="page.html" target="_blank" onclick="popup('variables');return false;">Click click</a> One popular use of the
javascript: pseudo-URL is offering a "previous page" option - when you don't know what the previous page is the person has come for. For example: <a href="javascript:history.go(-1)">Back</a> In this case, it would be better in usability terms to write the link out with Javascript document.write, and tell the user to click the back button if they have Javascript disabled - something vaguely like:
<script type="text/javascript">document.write('<a href="javascript:history.go(-1)">Click here to go to the previous page</a> or')</script> Click the "back" button. That way, users without Javascript don't get a broken (for them) link.
encyclo, I'm confused by your typification of the pseudo-URL as "deprecated". The p-U is a browser feature, not a language or markup specification. Who's doing the deprecation?