I am facing a issue when a user holds F5 for 10-15 minutes the web page becomes unresponsive and finally IIS throws an error.
To manage this, I want to restrict the user from pressing F5(lock F5 event) after certain number of times. After some time interval say 5 minutes I want to enable the refresh functionality(unlock F5 event).
I am using a cookie to save the number of times user presses F5. To handle cookie I am using the code mentioned here.
Assign a event to check if F5 keypress.
$(document).on("keydown", tryingF5);
I am using a variable to hold the cookie value and incrementing it once user presses F5.
var numberOfF5Click = 1;
var thresholdClick = 10;
var numberOfF5Click = 1;
function tryingF5(e) {
if ((e.which || e.keyCode) == 116) {
//alert(numberOfF5Click);
if (numberOfF5Click > thresholdClick) {
e.preventDefault();
alert("Multiple refresh has been prevented for some time!!");
}
numberOfF5Click = numberOfF5Click + 1;
docCookies.setItem("NumberOfF5Click", numberOfF5Click);
//alert("F5 Clicked =" + numberOfF5Click);
};
};
The complete code is setup here : JSBin
Question: The code is not working as expected, something is n and How could I do it better ?