How Should The Return Value Of Javascript Links Be Handled?
Solution 1:
From Web Applications API §6.1.5:
The following explains why clicking the links replaces the document content:
If the result of executing the script is void (there is no return value), then the URL must be treated in a manner equivalent to an HTTP resource with an HTTP 204 No Content response.
Otherwise, the URL must be treated in a manner equivalent to an HTTP resource with a 200 OK response whose Content-Type metadata is text/html and whose response body is the return value converted to a string value.
This behavior can also be demonstrated easily by simply pasting javascript:"Hello World";
in the address bar. Same goes for javascript:(function() { return "Hello World";})()
.
And the following explains why only your 1 and 2 code snippets are actually doing something.
Let the script source be the string obtained using the content retrieval operation defined for javascript: URLs
Post a Comment for "How Should The Return Value Of Javascript Links Be Handled?"