Created
March 23, 2014 08:50
-
-
Save robozevel/9720500 to your computer and use it in GitHub Desktop.
Stop propagation of the ESC key event when closing a file selection dialog
This file contains 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
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<label for="uploadFile">UPLOAD</label> | |
<input type="file" id="uploadFile"/> | |
<script> | |
$("input[type='file']").on("keyup", function(e) { | |
if (e.keyCode === 27) this.blur(), e.stopPropagation(); | |
}); | |
$(document).on("keyup", function(e) { | |
// The active element (i.e. focused) should be the <body> element | |
if (e.keyCode === 27) console.log(document.activeElement); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works Great ! 👍