Why don't browsers throw an error when any other word is used in place of 'javascript' in the value of onclick?

JavascriptHtml

Javascript Problem Overview


I inherited a website, and just came across this curiosity:

<a href="/delete"  onClick="jamoscript:return confirm('Do you really want to do that?');">Delete all</a>

I can display the page containing it and click the link to get the confirmation dialog box exactly the same as I do when I change "jamoscript" to "javascript". No diagnostics are displayed in the Firebug console, either when the page is loaded or when the link is clicked. What the hey? Googling for jamoscript doesn't turn up anything interesting.

Can anybody explain this behavior?

Javascript Solutions


Solution 1 - Javascript

The string value of an "onclick" attribute is taken to be simple JavaScript code. JavaScript includes provisions for labeled statements, so that code is a return statement with the label "jamoscript". In other words, this:

jamoscript: return confirm("Do you really want to hurt me?");

is perfectly legal JavaScript. Labels aren't used much, so they're unfamiliar.

The only context in which the "javascript:" prefix matters is when a URL is expected, as is the case with the "href" attribute of <a> tags.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsootsnootView Question on Stackoverflow
Solution 1 - JavascriptPointyView Answer on Stackoverflow