document.onkeydown = function() {
switch (event.keyCode) {
case 116 : //F5 button
event.returnValue = false;
event.keyCode = 0;
return false;
case 82 : //R button
if (event.ctrlKey) {
event.returnValue = false;
event.keyCode = 0;
return false;
}
}
}
Same as before, you can add this to your main javascript file and place it in the head part of your page.
It works by adding a function to your page's onkeydown event. Then we simply get which button was pressed by using event.Keycode (116 for F5 and 82 for R). Also, notice the "if" statement for R, it simply checks if the control button was pressed at the same time as R by checking event.ctrlKey.
But there's a limitation to handling page refreshes with this code. You simply cannot control the refresh button specific to your browsers' toolbar.
So the only way to really prevent users to refresh the page is by using this code and at the same time opening your page at a new window without the toolbar.
Check http://codingresource.blogspot.com/2010/01/javascript-windowopen-in-net.html for more info on how to do that.



