Prevent BACKSPACE from navigating back with jQuery (Like Google’s Homepage)

I would bind an event handler to keydown and prevent the default action of that event if we’re dealing with the backspace key outside of a textarea or input:

$(document).on("keydown", function (e) {
    if (e.which === 8 && !$(e.target).is("input, textarea")) {
        e.preventDefault();
    }
});

Leave a Comment

tech