0

In my dynamic web application Backspace is acting as page back in Chrome and I wanted to block this or at least warn the user about leaving the page, in case it was unintentional.

Please help me.

anil
  • 57
  • 2
  • 10

1 Answers1

0

Its a possible duplicate of How can I prevent the backspace key from navigating back?

// Prevent the backspace key from navigating back.
$(document).unbind('keydown').bind('keydown', function (event) {
    var doPrevent = false;
    if (event.keyCode === 8) {
        var d = event.srcElement || event.target;
        if ((d.tagName.toUpperCase() === 'INPUT' && 
             (
                 d.type.toUpperCase() === 'TEXT' ||
                 d.type.toUpperCase() === 'PASSWORD' || 
                 d.type.toUpperCase() === 'FILE' || 
                 d.type.toUpperCase() === 'SEARCH' || 
                 d.type.toUpperCase() === 'EMAIL' || 
                 d.type.toUpperCase() === 'NUMBER' || 
                 d.type.toUpperCase() === 'DATE' )
             ) || 
             d.tagName.toUpperCase() === 'TEXTAREA') {
            doPrevent = d.readOnly || d.disabled;
        }
        else {
            doPrevent = true;
        }
    }

    if (doPrevent) {
        event.preventDefault();
    }
});
Community
  • 1
  • 1
Brij Raj Singh - MSFT
  • 4,903
  • 7
  • 36
  • 55