Presumably, this is the URL of a resource accessible via the javascript protocol, just as you can have http: or ftp:. I do not know if this is the actual standard, but most browsers understand that the URL must be passed to the JavaScript interpreter. Thus, in practice, you can use it for JavaScript code that runs by reference, for example:
<a href="javascript:alert('Hello!')">Say hello</a>
Of course, writing JavaScript code inside HTML tags is neither clean nor durable. But there is an opportunity.
How about href="javascript:;" ? If you pay close attention, you will understand that ";" this is a piece of JavaScript code that, well, does nothing. This is the point. This is often used for links that do not indicate anywhere. The main goal is that clicking on it invokes JavaScript code defined elsewhere (via onclick event handlers).
Last but not least, you often see things like onclick="javascript:doStuff()" . The HTML onclick attribute expects Javascript code, not a URL. In this situation, the javascript: prefix javascript: completely redundant. However, the code still works. This is by chance a shortcut in JavaScript syntax; -)
Álvaro González
source share