JS Disable the "Backspace" key (that is, prevent the page backwards)

Source: Internet
Author: User

A problem that the project encounters
A normal web page, if there is no focus on this page, then click on the "Backspace" button, the page will be rolled back (backward to the previous page),
This will be a problem, when I entered in an input box, entered a number of characters, began to click the "Backspace" key to delete,
When the character in the text box is deleted, pressing the "Backspace" key reverses the previous page, but I don't want to go back to the previous page. So that users
The experience is very bad, and the user has to re-enter from the previous page.
Cause: When there is no focus on the page, clicking the "Backspace" button will return the page (this is a feature of the browser). When we are deleting
Enter the character of the box, when the deletion is finished, and then click on the "Backspace" key, the input box and the page will lose focus, then continue to click
The previous page is returned.
Workaround: We can define a KeyUp keyboard event function, which defines when the "Backspace" key is clicked, if the contents of the input box are empty,
Then keep getting the focus, and the input box will always hold the focus, so it won't go back to the previous page.

JS Disable the "Backspace" key (that is, prevent the page backwards)

Related Article

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.