What does the JavaScript pseudo protocol actually do? [duplicate]

The JavaScript: TYPE/LABEL/PREFIX (could not find the actual name for it) in the event handler serves one purpose only:

In IE, IFF the FIRST script on the page is NOT JavaScript, inline JavaScript on the rest of the page had (still has?) to have javascript: prefixing it.

It is not to be confused with the javascript: protocol in the href (which by the way also should be avoided). href="https://stackoverflow.com/questions/10068781/javascript:..." is only ever needed in old netscapes in the AREA tag. When you see the href="https://stackoverflow.com/questions/10068781/javascript:void(0)" someone needs to use onclick="....; return false" instead unless they put it there to alert the user that the link is a javascript driven one. It will fail if JS is turned off.

I looked for the official documentation from msdn, but here are discussions to back me up:

Calling VBScript from Javascript

Internet Explorer defaults to the language of the first script element
it parses. So if the first script element is javascript, you shouldn’t
need to specify “javascript:” in your event handler.

http://www.webdeveloper.com/forum/archive/index.php/t-135462.html

You have to tell IE you are using VBS AND JScript, otherwise the
assumption is all functions are VBS in this instance. Either add a
(empty?) JavaScript script element [at the top of your page] or use the jscript: protocol on the
onchange.
onchange=”jscript:location.hash=this[this.selectedIndex].value;”

Example

<html>
<head>
<script language="VBScript">
' some vbscript here forces the default language
' of the page to be VBScript and not jScript/JavaScript
</script>
</head>
<body onload="javascript:alert('I am inline in an event handler - boo me')">
.
.
<a href="https://stackoverflow.com/questions/10068781/..." onclick="javascript:alert('and so am I'); return false">Click</a>
.
<a href="javascript:alert('javascript: PROTOCOL is NOT the same (but avoid it too)')">
  Click
</a>


</body>
</html> 

Leave a Comment