Sometimes when we fill online form and by mistake we press the backspace button it take us to the previous page and the data filled by us get lost.so by using the following jquery code we can disable backspace button to work as back button of browser.This code will disable baspace button as back button if we have clicked outside any input field in the browser and if focus is on textfield or textarea it will behave as usual.
<script type="text/javascript">
$(document).keydown(function(e) {
var element = e.target.nodeName.toLowerCase();
if (e.keyCode === 8) {
if ((element != 'input' && element != 'textarea') || (element == 'input' && $(e.target).attr("type")== 'radio')|| (element == 'input' && $(e.target).attr("type")== 'checkbox')) {
return false;
}
}
});
</script>
<script type="text/javascript">
$(document).keydown(function(e) {
var element = e.target.nodeName.toLowerCase();
if (e.keyCode === 8) {
if ((element != 'input' && element != 'textarea') || (element == 'input' && $(e.target).attr("type")== 'radio')|| (element == 'input' && $(e.target).attr("type")== 'checkbox')) {
return false;
}
}
});
</script>