-1
我正在编写一个交互式应用程序,用户使用键盘执行操作。大部分击键都被正确捕捉并执行,但在按下按钮(ctrl + t)时会打开一个新选项卡,而不是调用我的按键事件。在那里,因为它完美的作品在Firefox和Internet Explorer,这里是示例代码无法防止Chrome浏览器上的按键快捷方式
<html>
<head>
<style>
#section {
width: 80%;
height: 500px;
background: grey;
margin: auto;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#section").keydown(function(e) {
stopEvent(e);
console.log(e.key + " down");
});
function stopEvent (e) {
e.stopPropagation();
e.preventDefault();
}
});
</script>
</head>
<body>
<div id="section" tabindex="1">
<h2>Keyboard operations</h2>
</div>
</body>
</html>
这完全取决于浏览器厂商。如果它落在计算机实际使用的范围之内,他们不应该用JavaScript来阻止它。 – PHPglue
IE和Firefox允许这样做的事实是非常令人惊讶的。预防ctrl-t我不希望能够预防。 – Keith
我同意。我想他们认为你仍然可以移动你的鼠标,如果你想要一个新的标签。 – PHPglue