What is the use of javascript: methodName (); in the anchor link?

What is the use of javascript: methodName (); in binding?

I saw the following in some code. What is the "javascript:"?

<a href="#" onclick="javascript:getUserName()"/>Click</a> 

It works if in both (with the condition "javascript:") and without it.

+1
javascript html
Aug 12 '13 at 11:39 on
source share
1 answer

In this case, javascript: is label :

Provides a statement with an identifier that you can reference using a break or continue statement.

For example, you can use a label to identify a loop, and then use the break or continue statements to indicate whether the program should interrupt the loop or continue execution.

In this case, it is useless, and instead of javascript you can use any other word.

This is probably only (erroneous!), Because it is usually visible in the href attribute (where javascript: is a pseudo-scheme):

 href="javascript:getUserName()" 

but it has a completely different meaning in the on* attributes.

Related: Do you need to specify "javascript:" in onclick?

+5
Aug 12 '13 at 11:40 on
source share



All Articles