I know this isn't an hard answer to find but i want to disable page refresh in browser. I am developing an exam application where when users start test, it will open up in a new window. but i don't want users to refresh this test page.
I could do this using below JavaScript code:
document.onkeydown = function (e) {
var key;
if (window.event) {
key = event.keyCode
} else {
var unicode = e.keyCode ? e.keyCode : e.charCode
key = unicode
}
switch (key) { //event.keyCode
case 116:
//F5 button
alert("11");
event.returnValue = false;
key = 0; //event.keyCode = 0;
return false;
case 82:
//R button
if (event.ctrlKey) {
alert("11");
event.returnValue = false;
key = 0; //event.keyCode = 0;
return false;
}
}
}
but when users go to the location/url bar and focus it and hit f5 button, page refreshes. Not just f5 but for shift+f5, browser shows same behaviour. how to avoid this?
Please help.