-1

What is the advantage of using

javascript: fun()

vs

fun()

in an inline event handler function?

Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Deepak Ingole
  • 14,912
  • 10
  • 47
  • 79

1 Answers1

0

javascript: is a protocol, to be used when a URL is required, e.g.:

<a href="javascript:fun();return false;">have fun</a>

If the JS is in an event handler attribute you shouldn't place the javascript: protocol before your code. E.g.:

<a href="#" onclick="fun();">have fun</a>
Web_Designer
  • 72,308
  • 93
  • 206
  • 262