编程语言
首页 > 编程语言> > javascript获取用户按了哪个键

javascript获取用户按了哪个键

作者:互联网

 

浏览器好像不允许js获取F5这个键的按下事件,应该屏蔽了,这个键太过特殊,猜测可能是,防止用户失去对浏览器的控制?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <meta charset="utf-8" />
</head>
<body onkeypress="checkKey(event)">
    dsfsdfasdfasdfa
    <script type="text/javascript">
        function checkKey(event) {
            keynum = window.event ? event.keyCode : event.which;
            keychar = String.fromCharCode(keynum);
            alert(keynum + ':' + keychar);
            console.log(event);
            console.log(this)
            //alert("event");
            if (keynum == 116) {
                alert("想刷新?");
                return false;
            }
        }
    </script>
</body>
</html>

 

标签:console,log,keychar,javascript,用户,alert,获取,keynum,event
来源: https://www.cnblogs.com/Tpf386/p/11405650.html