Created
May 18, 2011 03:18
-
-
Save harshkn/977936 to your computer and use it in GitHub Desktop.
Focus MainTextBox on load with backspace functionality
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
| window.onload = function () { | |
| // focus on the input field for easy access... | |
| var input = document.getElementById ('focusme'); | |
| input.focus (); | |
| // ...but if someone wishes to go back in their history, let them! | |
| document.onkeydown = function (e) { | |
| if (!e) { | |
| var e = window.event; | |
| } | |
| if (e.keyCode === 8 && !input.value) { | |
| history.back(); | |
| } | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment