Top Ad unit 728 × 90

Latest

random

Disable F5 Key Using jQuery

Disable Browser Refresh Button using JavaScript

In this blog post I will share a tip to prevent user refreshing the browser using keyboard f5 function key using jQuery. It works well with IE8, IE9, Mozilla14 and Chrome26 browser as well. Find the javascript code snippet below :-

disable f5 key using jquery,javascript f5 refresh event,javascript prevent page refresh on submit,javascript disable meta refresh,disable browser refresh button using javascript,how to disable refresh button of browser using jquery
javascript disable meta refresh

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to Block Refresh Key (F5) in JavaScript</title>

    <script type="text/javascript">

        var version = navigator.appVersion;

        function showKeyCode(e) {
            var keycode = (window.event) ? event.keyCode : e.keyCode;

            if ((version.indexOf('MSIE') != -1)) {
                if (keycode == 116) {
                    event.keyCode = 0;
                    event.returnValue = false;
                    return false;
                }
            }
            else {
                if (keycode == 116) {
                    return false;
                }
            }
        }

    </script>

</head>
<body onload="JavaScript:document.body.focus();" onkeydown="return showKeyCode(event)">
    <form id="form1" runat="server">
    <div>
        Demo ..
    </div>
    </form>
</body>
</html>

2 comments:

All Rights Reserved by Etechpulse © 2012 - 2016
Powered By Blogger

Contact Form

Name

Email *

Message *

Powered by Blogger.