How does js disable the Backspace key to bring the browser back? jsbackspace

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.