Stop BackSpace key from going back in IE and Firefox

While using AJAX some users would press the backspace button on their keyboard and the browser would go back so they would loose what they where doing in the ajax refreshed page ..... the SOLUTION (keep reading):
add the following code to the header of my masterpage:

  <script type="text/javascript">
    //code to catch the backspace and stops the back default action
if (typeof window.event == 'undefined'){
   document.onkeypress = function(e){
var test_var=e.target.nodeName.toUpperCase();
if (e.target.type) var test_type=e.target.type.toUpperCase();
if ((test_var == 'INPUT' && test_type == 'TEXT') ||(test_var == 'INPUT' && test_type == 'PASSWORD')|| test_var == 'TEXTAREA'){
  return e.keyCode;
}else if (e.keyCode == 8){
  e.preventDefault();
}
   }
}else{
   document.onkeydown = function(){
var test_var=event.srcElement.tagName.toUpperCase();
if (event.srcElement.type) var test_type=event.srcElement.type.toUpperCase();
if ((test_var == 'INPUT' && test_type == 'TEXT') ||(test_var == 'INPUT' && test_type == 'PASSWORD') || test_var == 'TEXTAREA'){
  return event.keyCode;
}else if (event.keyCode == 8){
  event.returnValue=false;
}
   }
}
    </script>

This solution works greate on Firefox, IE 6 and IE 7.