Skip to content

Instantly share code, notes, and snippets.

@robozevel
Created March 23, 2014 08:50
Show Gist options
  • Save robozevel/9720500 to your computer and use it in GitHub Desktop.
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
<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>
@william-abboud
Copy link

Works Great ! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment