javascript - What determines if `return false` in link's onclick attribute prevents navigation? -
link 1 not show example site, link 2 will. why?
see fiddle code below:
js:
function myalert(what) { alert(what); } html:
<a href="http://www.example.com" onclick="alert('link 1');return false;">link 1</a> <a href="http://www.example.com" onclick="myalert('link 2');return false;">link 2</a>
when viewing fiddle, open js console (f12 on windows). click second link.
you should see uncaught referenceerror: myalert not defined. because myalert not in global scope; jsfiddle scopes js code onload block automatically. can of course change no wrap - in head correct behavior.
here's working version of fiddle: http://jsfiddle.net/krd2b/
Comments
Post a Comment