Solve the Problem of clicking backspace and returning to the previous page

Source: Internet
Author: User
Do not click backspace to return to the previous page * window. onloadfunction () {document. getElementsByTagName (& amp; quot; body & amp; quot;) [0]. onkeydownfunction (){... the Code is as follows:
/**
*
* Do not click backspace to return to the previous page.
*/
Window. onload = function (){
Document. getElementsByTagName ("body") [0]. onkeydown = function (){

// Obtain the event object
Var elem = event. relatedTarget | event. srcElement | event.tar get | event. currentTarget;

If (event. keyCode = 8) {// judge that the key is the backSpace key.

// Obtain the element pointed to by pressing the time mark on the key.
Var elem = event. srcElement | event. currentTarget;

// Determine whether to prevent the default transfer of events that press the keyboard
Var name = elem. nodeName;

If (name! = 'Input' & name! = 'Textea '){
Return _ stopIt (event );
}
Var type_e = elem. type. toUpperCase ();
If (name = 'input' & (type_e! = 'Text' & type_e! = 'Textea '& type_e! = 'Password' & type_e! = 'File ')){
Return _ stopIt (event );
}
If (name = 'input' & (elem. readOnly = true | elem. disabled = true )){
Return _ stopIt (event );
}
}
}
}
Function _ stopIt (e ){
If (e. returnValue ){
E. returnValue = false;
}
If (e. preventDefault ){
E. preventDefault ();
}

Return false;
}
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.