If you specify javascript: something
as a value of href
attribute, this something
will be evaluated when someone activates that link.
The result of this evaluation will be checked: if its typeof
evaluates to 'undefined'
string, nothing will happen; if not, the page will be reloaded with the evaluation's result as its content:
<a href="javascript: void(0);">Nothing to see here, move along...</a>
<a href="javascript: undefined;">No, still nothing...</a>
<a href="javascript: prompt('Where would you like to go today?');">Check this out!</a>
The first two links here will do basically nothing. But the third one is quite more interesting: whatever you enter in prompt
will be shown to you - even an empty string! But that's not all: if you click Cancel
, you would still see a new page - with null
printed (as cancelled prompt
returns null
, and, as you probably know, typeof null
is in fact object
; and null
converted to String is, well 'null'
).
It could get more interesting:
<a href="javascript: window.undefined = 333; void(0);">What happens here?</a>
<a href="javascript: window.undefined = 333; undefined;">And here?</a>
Well, here we still get nothing at the first link. But second link will show you 333 in IE8. :)
And that's, I suppose, answers your second question as well: typeof void(0) will always be undefined
. typeof undefined
could give you dragons if someone decided it's a good idea to reassign them to window.undefined
. )
... And yes, javascript: return false;
is just wrong: you cannot return from non-function environment. You probably confused it with onclick: return false
, but that's completely another story. )