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
3
function 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>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2 Then and the onkeydown="return CheckShortcut()" into the <body> tag.
That's ok . work well!