3

I don't write inline javascript, but I see and work with it all the time in code bases that I work with:

<div onClick='javascript:alert("asdf");'></div>

I did some tests and found that in all my browsers, even IE in IE5 mode, you can change javascript to literally anything, and the alert will fire just fine.

<div onClick='qwerty:alert("asdf");'></div>

What is that delimiter? What is the history behind it? Is it ever needed or useful? I seem to remember that <script type="text/javascript"> doesn't really need the type attribute set, is that related to this, as well? I tried some googling around, but it's hard to search for.

MattDiamant
  • 8,561
  • 4
  • 37
  • 46
  • I believe this answers half your question: http://programmers.stackexchange.com/a/62118 – Dave Mar 13 '13 at 22:40

2 Answers2

6

It is a label that is ONLY needed in IE if the first script on the page is VBScript
If you add <script type="VBScript"></script> to (older?) IEs your later scripts will fail if they are javascript specific and do not have the label javascript: to tell IE to switch back

See my answer here: What does the JavaScript pseudo protocol actually do?

Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236
2

In general it's simply a label, analogous to:

label:
  statement;

Which is why qwerty:alert("asdf") works because it is legal Javascript.

IE does handle this differently; you can find more details in this answer.

Related answers and links:

Community
  • 1
  • 1
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295