Some answers here claim that the prefix "javascript:" is "left over from the old days", implying that it is intentionally specially handled by browsers for backward compatibility. Is there any solid evidence that this is so (did anyone check the source code)?
<span onclick="javascript:alert(42)">Test</span>
For me, it just reads like:
javascript: alert(42);
The meaning is that "javascript:" is just a tag and has no effect. This also works:
<span onclick="foobar:alert(42)">Test</span>
Update:
I experimented a bit, and it turns out that yes, "javascript:" is specially processed by IE, but definitely not like that - Firefox, Safari, Opera or Chrome:
<span onclick="javascript:while (true) { alert('once'); break javascript; }">Test</span>
In non-IE, this will simply warn "once" once, and then exit the loop. In IE, I get a "Shortcut not found" error. Works fine in all browsers:
<span onclick="foo:while (true) { alert('once'); break foo; }">Test</span>
Update 2:
I just understood the link http://crisp.tweakblogs.net/blog/the-useless-javascript-pseudo-protocol.html in one of the answers above, says a lot about the same.
Ates Goral Dec 16 '08 at 18:53 2008-12-16 18:53
source share