<p>I've been making a concerted effort to improve my javascript skills lately by reading as much javascript code as I can. In doing this I've sometimes seen the <code>javascript:</code> prefix appended to the front of event handler attributes in HTML element tags. What's the purpose of this prefix? Basically, is there any appreciable difference between:</p>

<pre><code>onchange="javascript: myFunction(this)"
</code></pre>

<p>and</p>

<pre><code>onchange="myFunction(this)"
</code></pre>

<p>?</p>

[{'answer_id': 23222, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 5, 'selected': True, 'text': '<p>Probably nothing in your example. My understanding is that <code>javascript:</code> is for anchor tags (in place of an actual <code>href</code>). You\'d use it so that your script can execute when the user clicks the link, but without initiating a navigation back to the page (which a blank <code>href</code> coupled with an <code>onclick</code> will do).</p>\n\n<p>For example:</p>\n\n<pre><code>&lt;a href="javascript:someFunction();"&gt;Blah&lt;/a&gt;\n</code></pre>\n\n<p>Rather than:</p>\n\n<pre><code>&lt;a href="" onclick="someFunction();"&gt;Blah&lt;/a&gt;\n</code></pre>\n'}, {'answer_id': 23237, 'author': 'Henrik Paul', 'author_id': 2238, 'author_profile': 'https://Stackoverflow.com/users/2238', 'pm_score': 1, 'selected': False, 'text': '<p>I am no authority in JavaScript, and perhaps more of a dunce than the asker, but AFAIK, the difference is that the <code>javascript:</code> prefix is preferred/required in URI-contexts, where the argument may be as well a traditional HTTP URL as a JavaScript trigger.</p>\n\n<p>So, my intuitive answer would be that, since <code>onChange</code> expects JavaScript, the <code>javascript:</code> prefix is redundant (if not downright erroneous). You can, however, write <code>javascript:myFunction(this)</code> in your address bar, and that function is run. Without the <code>javascript:</code>, your browser would try to interpret <code>myFunction(this)</code> as a URL and tries to fetch the DNS info, browse to that server, etc...</p>\n'}, {'answer_id': 23239, 'author': 'AnnanFay', 'author_id': 2118, 'author_profile': 'https://Stackoverflow.com/users/2118', 'pm_score': 0, 'selected': False, 'text': "<p>I don't know if the <code>javascript:</code> prefix means anything within the <code>onevent</code> attributes but I know they are annoying in anchor tags when trying to open the link in a new tab. The <code>href</code> should be used as a fall back and <strong>never</strong> to attach javascript to links.</p>\n"}, {'answer_id': 23242, 'author': 'mercutio', 'author_id': 1951, 'author_profile': 'https://Stackoverflow.com/users/1951', 'pm_score': 3, 'selected': False, 'text': '<blockquote>\n  <p>It should only be used in the href tag.</p>\n</blockquote>\n\n<p>That\'s ridiculous.</p>\n\n<p>The accepted way is this:</p>\n\n<pre><code>&lt;a href="/non-js-version/" onclick="someFunction(); return false"&gt;Blah&lt;/a&gt;\n</code></pre>\n\n<p>But to answer the OP, there is generally no reason to use <code>javascript:</code> anymore. In fact, you should attach the javascript event from your script, and not inline in the markup. But, that\'s a purist thing I think :-D</p>\n'}, {'answer_id': 23244, 'author': 'Chris Marasti-Georg', 'author_id': 96, 'author_profile': 'https://Stackoverflow.com/users/96', 'pm_score': 4, 'selected': False, 'text': '<p>It should not be used in event handlers (though most browsers work defensively, and will not punish you).  I would also argue that it should not be used in the href attribute of an anchor.  If a browser supports javascript, it will use the properly defined event handler.  If a browser does not, a javascript: link will appear broken.  IMO, it is better to point them to a page explaining that they need to enable javascript to use that functionality, or better yet a non-javascript required version of the functionality.  So, something like:</p>\n\n<pre><code>&lt;a href="non-ajax.html" onclick="niftyAjax(); return false;"&gt;Ajax me&lt;/a&gt;\n</code></pre>\n\n<p>Edit: Thought of a good reason to use javascript:.  Bookmarklets.  For instance, this one sends you to google reader to view the rss feeds for a page:</p>\n\n<pre><code>var b=document.body;\nif(b&amp;&amp;!document.xmlVersion){\n  void(z=document.createElement(\'script\'));\n  void(z.src=\'http://www.google.com/reader/ui/subscribe-bookmarklet.js\');\n  void(b.appendChild(z));\n}else{\n  location=\'http://www.google.com/reader/view/feed/\'+encodeURIComponent(location.href)\n}\n</code></pre>\n\n<p>To have a user easily add this Bookmarklet, you would format it like so:</p>\n\n<pre><code>&lt;a href="javascript:var%20b=document.body;if(b&amp;&amp;!document.xmlVersion){void(z=document.createElement(\'script\'));void(z.src=\'http://www.google.com/reader/ui/subscribe-bookmarklet.js\');void(b.appendChild(z));}else{location=\'http://www.google.com/reader/view/feed/\'+encodeURIComponent(location.href)}"&gt;Drag this to your bookmarks, or right click and bookmark it!&lt;/a&gt;\n</code></pre>\n'}, {'answer_id': 23342, 'author': 'Shadow2531', 'author_id': 1697, 'author_profile': 'https://Stackoverflow.com/users/1697', 'pm_score': 1, 'selected': False, 'text': '<p>javascript: in JS code (like in an onclick attribute) is just a label for use with continue/goto label statements that may or may not be supported by the browser (probably not anywhere). It could be zipzambam: instead. Even if the label can\'t be used, browsers still accept it so it doesn\'t cause an error.</p>\n\n<p>This means that if someone\'s throwing a useless label in an onclick attribute, they probably don\'t know what they\'re doing and are just copying and pasting or doing it out of habit from doing the below.</p>\n\n<p>javascript: in the href attribute signifies a Javascript URI.</p>\n\n<p><a href="http://shadow2531.com/js/jsuri.html" rel="nofollow noreferrer">Example</a>:</p>\n\n<pre><code>javascript:(function()%7Balert(%22test%22)%3B%7D)()%3B\n</code></pre>\n'}, {'answer_id': 23365, 'author': 'Polsonby', 'author_id': 137, 'author_profile': 'https://Stackoverflow.com/users/137', 'pm_score': 0, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/questions/23217/whats-the-purpose-if-any-of-javascript-in-event-handler-tags#23242">@mercutio</a></p>\n\n<blockquote>\n  <blockquote>\n    <p>That\'s ridiculous.</p>\n  </blockquote>\n</blockquote>\n\n<p>No, it\'s not ridiculous, javascript: is a pseudo protocol that can indeed only be used as the subject of a link, so he\'s quite right. Your suggestion is indeed better, but the best way of all is to use unobtrusive javascript techniques to iterate over HTML elements and add behaviour programmatically, as used in libraries like jQuery.</p>\n'}, {'answer_id': 23466, 'author': 'Polsonby', 'author_id': 137, 'author_profile': 'https://Stackoverflow.com/users/137', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n  <blockquote>\n    <p>Basically, is there any appreciable difference between: <code>onchange="javascript: myFunction(this)"</code> and <code>onchange="myFunction(this)"</code> ?</p>\n  </blockquote>\n</blockquote>\n\n<p>Assuming you meant  <code>href="javascript: myFunction(this)"</code>, yes there is, especially when loading content using the javascript. Using the javascript: pseudo protocol makes the content inaccessible to some humans and all search engines, whereas using a real href and then changing the behaviour of the link using javascript makes the content accessible if javascript is turned off or not available in the particular client.</p>\n'}, {'answer_id': 32193, 'author': 'Russell Leggett', 'author_id': 2828, 'author_profile': 'https://Stackoverflow.com/users/2828', 'pm_score': 2, 'selected': False, 'text': '<p>The origins of <code>javascript:</code> in an event handler is actually just an IE specific thing so that you can specify the language in addition to the handler. This is because <code>vbscript</code> is also a supported client side scripting language in IE. Here\'s an example of <a href="http://www.visualbasicscript.com/m_50201/tm.htm" rel="nofollow noreferrer">"vbscript:"</a>.</p>\n\n<p>In other browsers (as has been said by Shadow2531) <code>javascript:</code> is just a label and is basically ignored.</p>\n\n<p><code>href="javascript:..."</code> can be used in links to execute javascript code as DannySmurf points out.</p>\n'}, {'answer_id': 43001, 'author': 'benc', 'author_id': 2910, 'author_profile': 'https://Stackoverflow.com/users/2910', 'pm_score': 0, 'selected': False, 'text': '<p>Flubba:</p>\n\n<p>Use of <code>javascript:</code> in <code>HREF</code> breaks "Open in New Window" and "Open in New Tab" in a Firefox and other browsers.</p>\n\n<p>It isn\'t "wrong", but if you want to make your site hard to navigate...</p>\n'}]
['https://Stackoverflow.com/questions/23217', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1680/']