Sunday, May 24, 2009

How to Prevent Users to Press F5 key (Refresh button)

Some times we want to prevent user to Press F5 key to prevent Page Refresh.
This Script works fine.(As i tested in IE.)
Paste this code in the Head Section of your Page

document.onkeydown =
function(){
if(window.event && window.event .keyCode == 116)
{
// Capture and remap F5
window.
event.keyCode = 505;
}
if(window.event && window.event .keyCode == 505)
{
// New action for F5
return false;
// Must return false or the browser will refresh anyway
} }