Javaweb page to prevent click Backspace page back _java

Source: Internet
Author: User

When the keyboard knocks down the back key (Backspace)

1, prevent the browser automatically back

2, but does not affect the password, single line text, multiline text input box, such as the fallback operation

<script type= "Text/javascript" >//Handling keyboard events prohibit back key (Backspace) password or single line, multiline text box exception function Banbackspace (e) {var ev = e | | window.event;//get Event object var obj = Ev.target | | ev.srcelement;//get event source var t = Obj.type | |  
Obj.getattribute (' type '); Get event Source Type//Get the event type as a condition of judgment var vreadonly = Obj.getattribute (' readonly ');  
var venabled = Obj.getattribute (' enabled '); Handling Null value condition Vreadonly = (Vreadonly = = null)?  
False:vreadonly; venabled = (venabled = null)?  
true:venabled; When the BACKSPACE key is hit, the event source type is a password or single line, multiline text,//And the ReadOnly property is True or the Enabled property is False, and the BACKSPACE key fails var flag1= (Ev.keycode = = 8 &&  
(t== "Password" | | t== "TEXT" | | t== "TEXTAREA") && (Vreadonly==true | | venabled!=true))? True:false; The BACKSPACE key fails var flag2= (Ev.keycode = 8 && t!= "password" && t!= "text" backspace when the event source type is not a password or a single line, multi-line text, when the key is tapped &A  
mp;& T!= "textarea")? True:false;  
Judge if (Flag2) {return false;  
} if (Flag1) {return false; }//No back key acts on Firefox, Opera Document.onkeYpress=banbackspace;  
Prohibit the back key role in IE, Chrome document.onkeydown=banbackspace;  </script>

The above is a small set to introduce the Javaweb page to prevent click Backspace page back, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.