1

We have lot of legacy inline javascript code for img onclick , href clicks ets and those clicks starts with javascript:

javascript:showpopup(); 

why do we need javascript: before calling the javascript functions.

any explanation will be appreciated.

kobe
  • 15,671
  • 15
  • 64
  • 91
  • You probably shouldn't use it at all. Just return false in your anchor tags. See http://stackoverflow.com/questions/2321469/when-do-i-need-to-specify-the-javascript-protocol – charliegriefer Dec 04 '10 at 06:22

2 Answers2

4

The javascript: scheme indicates to the browser that it's JavaScript code and not a relative path from the current page's base URL.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2

For inline event handlers like onclick or onmouseover you don't need the javascript: part.

<a href="javascript:you_need_it_here();" onmouseover="but_not_here();">Link</a>

Without javascript: in the href, clicking that link would try to take you to somewhere like this:

http://www.example.com/something/you_need_it_here();

See @Ignacio's answer for the reason.

Ken Redler
  • 23,863
  • 8
  • 57
  • 69