禁用backspace退格键的页面后退,但是可以删除文本内容

<script type="text/javascript">
/*禁用backspace键的后退功能,但是可以删除文本内容*/
document.onkeydown = check;
function check(e) {
    var code;
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    if (((event.keyCode == 8) &&                                                    //BackSpace 
         ((event.srcElement.type != "text" && 
         event.srcElement.type != "textarea" && 
         event.srcElement.type != "password") || 
         event.srcElement.readOnly == true)) || 
        ((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) ||    //CtrlN,CtrlR 
        (event.keyCode == 116) ) {                                                   //F5 
        event.keyCode = 0; 
        event.returnValue = false; 
    }
	return true;
}
</script>

 来自:http://hi.baidu.com/luo_qing_long/blog/item/42bfc81e0e2815184034175c.html

你可能感兴趣的:(JavaScript,html,Blog)