Reputation: 2685
What is javascript:
used for, and is it compliant and should I use it?
I noticed that some of my associates choose to use
javascript:
followed by some function name or some JavaScript code, but it seems unnecessary to me.
I see this a lot in event handlers like:
onclick="javascript: somefunction451();"
Also I have trouble searching for more information on javascript:
because it says that I'm trying to do cross site scripting. Especially if I stick it in quotes. Is this something that simply can't be fixed? Should I search this in a Flash only or Silverlight only browser?
Upvotes: 3
Views: 533
Reputation: 413826
It's completely unnecessary in "onfoo" attribute values. In that context, it's interpreted as a label by the JavaScript parser. Thus it's not erroneous, but it's useless.
In "href" values, it has a role, but there's really no reason for JavaScript "href" values anyway.
Upvotes: 7
Reputation: 17451
It's "unofficial" but "common" and "works in any modern browser" in the place of a URI scheme name per this source: http://en.wikipedia.org/wiki/URI_scheme
This would apply then to <a href="javascript:...
only. It's necessary there (but there are better ways to invoke javascript when clicking on an element).
In the onClick=
attribute and such, it is a label and unnecessary.
Upvotes: 1