1

Possible Duplicate:
When do I need to specify the JavaScript protocol?
onclick=“javascript:func()” vs. onclick=“func()”

What exactly is the difference between the two code examples below?

  1. <input type="button" value="click me" onclick="a()">

    and

  2. <input type="button" value="click me" onclick="javascript:a()">

    Where a() is any JavaScript function.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    Using `javascript:` there has the same effect as using `foobar:`: None. – Felix Kling Dec 11 '12 at 05:52
  • 1
    Both are equally bad practice and old fashioned – KooiInc Dec 11 '12 at 05:55
  • The only case where it is *necessary* is when you make a bookmarklet, in which case, by default, `http` is assumed as the protocol, which you might not want. – Anirudh Ramanathan Dec 11 '12 at 05:56
  • 1
    @Cthulhu: It's never necessary in inline event handlers. You were probably thinking about `a` elements and the `href` value. – Felix Kling Dec 11 '12 at 07:27
  • @FelixKling Yes, I said above that it was necessary esp. when making URLs for *bookmarks*, in which it is automatically assumed to be an `http` URI when devoid of protocol. in inline event handlers, unnecessary, agreed. – Anirudh Ramanathan Dec 11 '12 at 07:31

0 Answers0