解决点击backspace,返回上一页问题

参照 http://q821424508.iteye.com/blog/1587025

代码如下:
/**
*
* 禁止点击backspace 返回上一页
*/
window.onload=function(){  
   document.getElementsByTagName("body")[0].onkeydown =function(){ 
        
        //获取事件对象 
        var elem = event.relatedTarget || event.srcElement || event.target ||event.currentTarget;  
         
        if(event.keyCode==8){//判断按键为backSpace键 
         
                //获取按键按下时光标做指向的element 
                var elem = event.srcElement || event.currentTarget;  
                 
                //判断是否需要阻止按下键盘的事件默认传递 
                var name = elem.nodeName; 
                 
                if(name!='INPUT' && name!='TEXTAREA'){ 
                    return _stopIt(event); 
                } 
                var type_e = elem.type.toUpperCase(); 
                if(name=='INPUT' && (type_e!='TEXT' && type_e!='TEXTAREA' && 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; 
}

你可能感兴趣的:(js,backspace,返回上一页)