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(); } }; };