capture the backspace except in input and textare
One day,my costumer was operating the web site, He selected the button ,then he said :" I want to delete the button".I havn't said anyword, He had press the backspace key, then that web site want back to forward page. How to avoid this case?
1. Add the follow javascript code to the <head> tag.
2 Then and the onkeydown="return CheckShortcut()" into the <body> tag.
That's ok . work well!
1. Add the follow javascript code to the <head> tag.
1<script language="javascript">
2//capturing the backspace key
3function CheckShortcut()
4{
5 // add the code to body (onkeydown="return CheckShortcut()")
6 if((event.keyCode==8 || event.keyCode==13 )&&!document.activeElement.isTextEdit)
7 {
8 event.cancelBubble = true;
9 event.returnValue = false;
10 return false;
11 }
12}
13</script>
2//capturing the backspace key
3function CheckShortcut()
4{
5 // add the code to body (onkeydown="return CheckShortcut()")
6 if((event.keyCode==8 || event.keyCode==13 )&&!document.activeElement.isTextEdit)
7 {
8 event.cancelBubble = true;
9 event.returnValue = false;
10 return false;
11 }
12}
13</script>
2 Then and the onkeydown="return CheckShortcut()" into the <body> tag.
That's ok . work well!