js 禁止 F5 刷新页面

js 禁止 F5 刷新页面
<html>
<head>
    <script type="text/javascript">
        // 禁止F5刷新页面
        document.onkeydown = function () {
            /*
                (ctrlKey == true && keyCode == 82)   Ctrl+R   ---刷新
                (keyCode == 116)                     F5       ---刷新
                (ctrlKey == true && keyCode == 116)  Ctrl+F5  ---强制刷新
            */
            //window.alert(event.keyCode);
            var k = event.keyCode;
            if ((event.ctrlKey == true && k == 82) || (k == 116) || (event.ctrlKey == true && k == 116)) {
                // return (window.confirm("close?"));
                event.keyCode = 0;
                event.returnValue = false;
                event.cancelBubble = true;
            }
        }
    </script>
    <title></title>
</head>

<body>
</body>
</html>

热门推荐