How to Disable F5 Button Using jQuery

AuthorSumit Dey Sarkar

Pubish Date25 Aug 2022

categoryJQuery

In this tutorial, we will learn how to disable F5 button using jQuery.

How to Disable F5 Button using jQuery

Sometime we don't want to refresh web browser using F5 button, then we need to disable F5 button.

How to disable F5 button using jQuery

Here we use keydown event of jquery and use f5 key code 116 to disable F5 button.

<!DOCTYPE html>
<html>

<head>
  <title>How to disable F5 button using jQuery</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
</head>

<body>

  <h1 style="font-size:20px">How to disable F5 button using jQuery</h1>

  <script>
    $(document).ready(function () {
      $(window).keydown(function (event) {
        if (event.keyCode == 116) {
          event.preventDefault();
          return false;
        }
      });
    });
  </script>

</body>

</html>
Comments 0

Leave a comment