Prevent backspace from navigating back in AngularJS

后端 未结 4 1572
Happy的楠姐
Happy的楠姐 2021-01-12 12:03

I faced this issue in my AngularJS webapp.

When a user enters a page with a form to fill and he starts typing, if he presses the backspace key and the focus is not o

4条回答
  •  耶瑟儿~
    2021-01-12 12:41

    I got this answer here: How can I disabling backspace key press on all browsers?

    $(document).keydown(function(e) {
        var nodeName = e.target.nodeName.toLowerCase();
    
        if (e.which === 8) {
            if ((nodeName === 'input' && e.target.type === 'text') ||
                nodeName === 'textarea') {
                // do nothing
            } else {
                e.preventDefault();
            }
        }
    });
    

    Just put it inside your controller.

提交回复
热议问题