Created
March 16, 2011 19:47
-
-
Save gerad/873172 to your computer and use it in GitHub Desktop.
shows a bug with chrome event handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form onsubmit='alert("should not get here");'> | |
<input id="text" type="text" placeholder="type something and hit enter"> | |
</form> | |
<script> | |
var t = document.getElementById('text'); | |
t.addEventListener('keydown', function(e) { | |
if (e.which === 13) { // hitting return | |
alert('form submission should be prevented'); | |
e.stopPropagation(); | |
e.stopImmediatePropagation(); | |
e.preventDefault(); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you take out the 'form submission should be prevented' alert, the form submission is prevented
also, see http://jsfiddle.net/86maU/