DWQA QuestionsCategory: ProgramHow does ie11 shield backspace from returning to the previous page?
liujs asked 1 month ago

The code is as follows, which supports ie10 at most

$(document).ready(function(){  
    //Disable backspace for Firefox and opera   
    document.onkeypress = banBackSpace;  
    //Disable backspace for IE and chrome  
    document.onkeydown = banBackSpace;  
});  
//Handle keyboard events except for backspace passwords or single line, multi line text boxes   
function banBackSpace(e){  
    //alert(event.keyCode)  
    Var EV = e | window. Event; // get the event object     
    Var obj = ev.target | ev.srcelement; // get event source       
    Var t = obj. Type | obj. Getattribute ('type '); // get the event source type       
    //Get the event type as the judgment condition   
    var vReadOnly = obj.readOnly;  
    var vDisabled = obj.disabled;  
    //Handling undefined values   
    vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;  
    vDisabled = (vDisabled == undefined) ? true : vDisabled;  
    //When the backspace key is pressed, the event source type is password or single line, multi line text,    
    //If the readonly property is true or the disabled property is true, the backspace key will be invalid    
    var flag1 = ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vDisabled == true);  
    //When the backspace key is clicked, if the event source type is not password or single line or multi line text, the backspace key will be invalid      
    var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";  
    // judgement      
    if (flag2 || flag1)   
        Event. ReturnValue = false; // if return false is written here, the effect cannot be achieved   
}

When the mouse focuses on the text box, press the backspace key to return to the previous page, PS: the text box property is readonly
It has been solved. How can I close the problem? Solution: http://goo.gl/hx9hx3 can shield the backspace function of ie11 from returning to the previous page
How does ie11 shield backspace from returning to the previous page?

liujs replied 1 month ago

http://goo.gl/hX9hx3It can shield the function of ie11’s backspace to return to the previous page

3 Answers
Launch/The Start answered 1 month ago

Change to disabled
To completely block the browser’s backward events is also called to solve the problem?

fishenal answered 1 month ago

You might as well implement readonly in code to mask all Keydown events of input

$('input').keydown(function(e){
    e.preventDefault();
});
Xiao Shui answered 1 month ago

How to shield ie11? Landlord