I know that you can use a javascript: pseudo protocol for URLs in an <a> tag. However, I’ve noticed that Firefox and IE will both allow ‘javascript:‘ to precede javascript code within a <script> tag. Is this valid syntax? Does it change the scoping rules?
Examples: I’ve seen this many times:
<a onclick='javascript:alert('hello world!');'>Hello World!</a>
But is this legal/valid syntax and does it do anything special:
<script type='text/javascript'> javascript:alert('hello world!'); </script>
Outside of the
hrefattribute (where it is a protocol specifier), name: just creates a label (such as one might use with acontinueorbreak).See: Do you ever need to specify javascript: in an onclick?