Search code examples
javascriptdom-events

What is "javascript:" in a JavaScript event handler?


What is javascript: in a JavaScript event handler?

Such as:

<input onkeydown="javascript:return false;" type="text" name="textfield" />

Solution

  • It is a mistake. The pseudo-protocol is not needed in event handlers.

    On a URL (a element href attribute, for instance), if you enter javascript: and follow that with javascript, the browser will run the javascript code.

    For event handler, this is not needed, though the browser will not report an error.