Skip to content Skip to sidebar Skip to footer

Preventing Backspace To Go Back From The Current Form

I'm using the below JavaScript function to prevent backspace from going back. function preventBackspace(e) { var evt = e || window.event; if (evt) { var ke

Solution 1:

When the user is currently focused on a textbox, the backspace key does not cause the browser to go back. The backspace in a textbox is used to delete a character - and since you've added preventDefault(), you're stopping that behavior from happening.

If your goal is to prevent the user from accidentally leaving the form before they are finished, you can use window.onbeforeunload to display a warning message that allows the user to cancel navigation:

window.onbeforeunload = function() {
    return "Are you sure you want to leave this page?  Your current entries" +
        " will be lost.";
};

Post a Comment for "Preventing Backspace To Go Back From The Current Form"