Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is the 'javascript:' prefix valid syntax?

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>
like image 334
Heath Borders Avatar asked Feb 18 '09 15:02

Heath Borders


1 Answers

Outside of the href attribute (where it is a protocol specifier), name: just creates a label (such as one might use with a continue or break).

See: Do you ever need to specify javascript: in an onclick?

like image 143
Shog9 Avatar answered Oct 02 '22 19:10

Shog9