-11
<Script language="javascript">
function checkKeyCode(evt)
{

var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if(event.keyCode==116)
{
evt.keyCode=0;
return false
}
}
document.onkeydown=checkKeyCode;
</script> 

I tried this it is working fine in IE but it doesn't work in Firefox.................please help me.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 4
    You cant force anything on Users browser – techie_28 Sep 12 '12 at 10:30
  • WHY?! Refreshing is a fundamental function of a browser. Work *with* it, not against it. Also hint: F5 is only the Windows convention for "refresh". There are many more platforms out there and there's always a toolbar button that does the same. – deceze Sep 12 '12 at 10:33
  • Hai guys, actually my problem is whenever I refresh the form it is submitted again and it is throwing the exception, that's way I want to disable the refresh in my application. – Y.V. NARASIMHA RAO Sep 12 '12 at 10:43
  • this is not the way to fix your problem. on submission of the form, make immediately a redirect to another page, thus refreshing the target page won't cause you problems anymore. Another solution is to ignore repeated submissions. – armel Sep 12 '12 at 10:53
  • Twitter web site disables F5 – vkolodrevskiy May 07 '13 at 17:53

2 Answers2

4

Classic XY problem. You're asking for a solution to a problem to a non-solution to a problem that needs to be solved in a completely different way.

The correct pattern is called POST-redirect-GET. After each POST request (a form submit) you redirect the user to a different or even the same page, which causes a regular GET request. When the user then refreshes the page, a regular GET request will be issued without resubmitting the form.

See Trying to understand the Post/Redirect/Get design pattern (implemented with PHP) and similar questions for more details.

Community
  • 1
  • 1
deceze
  • 510,633
  • 85
  • 743
  • 889
0

With jquery

$(document).keypress(function(e){
  if(e.keyCode==116){
    return false;
   }
}
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186