title: prevent user from refreshing a page multiple times
body: <p>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.</p>
  
  <p>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).</p>
  
  <p>I am using a cookie to save the number of times user presses F5. To handle cookie I am using the code mentioned <a href="https://stackoverflow.com/a/24035852/769678">here</a>.</p>
  
  <p>Assign a event to check if F5 keypress.</p>
  
  <pre><code>$(document).on("keydown", tryingF5);
  </code></pre>
  
  <p>I am using a variable to hold the cookie value and incrementing it once user presses F5.</p>
  
  <pre><code>var numberOfF5Click = 1;
  var thresholdClick = 10;
  var numberOfF5Click = 1;
  function tryingF5(e) {
          if ((e.which || e.keyCode) == 116) {
              //alert(numberOfF5Click);
              if (numberOfF5Click &gt; thresholdClick) {
                  e.preventDefault();
                  alert("Multiple refresh has been prevented for some time!!");
              }
  
              numberOfF5Click = numberOfF5Click + 1;
              docCookies.setItem("NumberOfF5Click", numberOfF5Click);
  
              //alert("F5 Clicked =" + numberOfF5Click);
          };
      };
  </code></pre>
  
  <p>The complete code is setup here : <a href="http://jsbin.com/tukeyalusu/1/" rel="nofollow noreferrer">JSBin</a></p>
  
  <p>Question: The code is not working as expected, something is n and How could I do it better ?</p>