How does js disable the Backspace key to bring the browser back? jsbackspace
In the project, if you press the Backspace key to bring the browser back, several solutions are not ideal. Therefore, the wisdom of the masses and the wisdom of the family are summarized as follows:
1. Define the method to block Backspace in public js
Function banBackSpace (e) {var ev = e | window. event; // obtain the event object var obj = ev in various browsers. relatedTarget | ev. srcElement | ev.tar get | ev. currentTarget; // press the Backspace key if (ev. keyCode = 8) {var tagName = obj. nodeName // Tag Name // if the tag is not input or textarea, Backspace if (tagName! = 'Input' & tagName! = 'Textea ') {return stopIt (ev);} var tagType = obj. type. toUpperCase (); // tag type // in addition to the following types of input tags, all Backspace if (tagName = 'input' & (tagType! = 'Text' & tagType! = 'Textaga' & tagType! = 'Password') {return stopIt (ev );} // if the input or textarea INPUT box cannot be edited, The Backspace if (tagName = 'input' | tagName = 'textta') & (obj. readOnly = true | obj. disabled = true) {return stopIt (ev) ;}} function stopIt (ev) {if (ev. preventDefault) {// The preventDefault () method prevents elements from performing the default behavior ev. preventDefault ();} if (ev. returnValue) {// use window in IE browser. event. returnValue = false; this prevents default behavior of elements ev. returnValue = false;} return false ;}
The method annotations are clearly written. I will not explain them more here.
2. Call this method after page loading is complete.
$ (Function () {// intercepts the escape code. keypress shields these functions from pressing document. onkeypress = banBackSpace; // obtain document for function buttons. onkeydown = banBackSpace ;})
Note:Trigger sequence of key events: keydown-> keypress-> textInput-> keyup
Problem: After the select drop-down list is expanded, the keyboard event cannot be obtained. Press the Backspace key, and the browser will still roll back to the history. Solution: Change the select drop-down box to the combobox of easyUI;
The implementation method for disabling the Backspace key in this js document to bring the browser back is all the content that I have shared with you. I hope to give you a reference and support for the customer's house.