Thursday, May 31, 2007

Prevent browser F5 refresh

Few things are more annoying than needing to prevent your web site's visitors from refreshing a page resulting from a form "post".

This solution works with Internet Explorer. Simply place this code in the "head" section of your page.

<script language=javascript>
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
}
}
</script>
Refer your friends to this blog:
http://programmingcentral.blogspot.com/