How to Disable F5 Refresh Button using JQuery?
In this post, we will learn how to prevent or disable f5 refresh in javascript. sometime we does not want to browser refresh using f5 button for our web page. so you can disable f5 key in jquery. we can easily disable f5 button using javascript with example.
we will 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;
}
});
});
You can see bellow full example and demo file how it's disabled f5 refresh button. let's see code:
Example:
<!DOCTYPE html>
<html>
<head>
<title>How to disable f5 refresh button using jquery? - ItSolutionStuff.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? - ItSolutionStuff.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>
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Remove Key Value from Array using JQuery?
- How to Get Selected Radio Button Value in JQuery?
- JQuery Check If Value Exists or Not in Array Example
- How to Split String to Array By Comma using JQuery?
- Add Edit Delete Table Row Example using JQuery
- How to Disable Browser Back Button using JQuery?
- How to Get Selected Checkbox Value from Checkboxlist using JQuery?
- JQuery Disable Right Click, Cut, Copy and Paste Example
- How to Remove Empty or Null Values from Array in JQuery?
- JQuery - How to Push Specific Key and Value in Array?
- How to Remove All Spaces from String in JQuery?
- Laravel 11 JQuery Ajax Pagination Example
- How to Add Lazy Loading Image using JQuery?