According to standards, what's the correct way to handle the return value of javascript protocol href
links?
Some examples:
<a href='javascript:"Hello World";'> Click </a> <!-- return a String -->
<a href='javascript:ThisFunctionReturnsString();'> Click </a>
<a href='javascript:12345;'> Click </a> <!-- Number -->
<a href='javascript:[1, 2, 3, 4, 5];'> Click </a> <!-- Array -->
<a href='null;'> Click </a> <!-- null-->
<a href='undefined;'> Click </a> <!-- undefined-->
<a href='javascript:{};'> Click </a> <!-- Object -->
How should a standard-compliant browser handle the return values?
How do current browsers in the wild differ from this standard behavior?
From Web Applications API §6.1.5:
The following explains why clicking the links replaces the document content:
This behavior can also be demonstrated easily by simply pasting
javascript:"Hello World";
in the address bar. Same goes forjavascript:(function() { return "Hello World";})()
.And the following explains why only your 1 and 2 code snippets are actually doing something.