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

前端 未结 9 968
陌清茗
陌清茗 2020-11-30 22:48

Notice while on Google\'s homepage, with no focus on any element, pressing BACKSPACE will put the focus into the search toolbar instead of navigating back.

How can I

9条回答
  •  悲哀的现实
    2020-11-30 23:33

    Handled readonly text boxes also

    $(document).keydown(function (e) {
            var activeInput = $(document.activeElement).is("input[type=text]:not([readonly]):focus, textarea:focus");
            if (e.keyCode === 8 && !activeInput) {
                return false;
            };
        });
    

提交回复
热议问题