JQuery - Disable F5 Refresh Button Example

Jquery

Nicesnippets

4167

24-03-2021


JQuery - Disable F5 Refresh Button Example

Hello Friends,

Now let's see example of how to prevent or disable f5 refresh in jquery. If you want to browser refresh using f5 button for our web page then you can use bellow example. so you can disable f5 key in jquery. we can easily disable f5 button using javascript with example.

Here I will give you full example for disable f5 key using keydown event of jquery. as we know f5 key code is a 116, so basically if user will press 116 event.keyCode then we will simply preventDefault with return false.

we can simply write this code:

$(document).ready(function() {

$(window).keydown(function(event){

if(event.keyCode == 116) {

event.preventDefault();

return false;

}

});

});

Here I will give you full example and demo file how it's disabled f5 refresh button. let's see code:

<!DOCTYPE html>

<html>

<head>

<title>How to disable f5 refresh button using jquery? - NiceSnippets.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

</head>

<body>

<div class="container">

<h1>How to disable f5 refresh button using jquery? - NiceSnippets.com</h1>

</div>

<script type="text/javascript">

$(document).ready(function() {

$(window).keydown(function(event){

if(event.keyCode == 116) {

event.preventDefault();

return false;

}

});

});

</script>

</body>

</html>

It will help you....


Recommended Posts