防止默认'F1'iE11中的事件
prevent default 'F1' event in iE11
当用户按下F1键时,我计划显示我们的应用程序帮助并取消默认操作。我尝试了不同的选项不显示IE的帮助弹出窗口。这是我的代码:
document.addEventListener('keydown', function (e) {
if (e.key === 'F1' || e.keyCode == 112) {
e.cancelBubble = true;
e.cancelable = true;
e.stopPropagation();
e.preventDefault();
e.returnValue = false;
//my help menu code goes here
}
});
请让我知道如何实现显示我的应用程序的帮助页面,而不是IE帮助。我使用的是IE11版本。
您可以订阅window.onhelp
事件:
window.onhelp =function() {
alert();
return false;
}
尝试执行此
<script>
$(document).ready(function () {
removedefaulthelp();
function removedefaulthelp()
{
window.onhelp = function () {
return false;
alert();
}
}
document.addEventListener('keydown', function (e) {
if (e.key === 'F1' || e.keyCode == 112) {
removedefaulthelp();
e.cancelBubble = true;
e.cancelable = true;
e.stopPropagation();
e.preventDefault();
e.returnValue = false;
//my help menu code goes here
}
});
}
</script>
有关更多信息,请参阅此。
这里有一个类似于Sukanya答案的例子,但我的解决方案显示了如何扩展F2-F12键,并故意忽略F-组合键,例如CTRL+F1。
<html>
<head>
<!-- Note: reference your own JQuery library here -->
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
</head>
<body>
<h1>F-key trap example</h1>
<div><h2>Example: Press the 'F1' key to open help</h2></div>
<script type="text/javascript">
//uncomment to prevent on startup
//removeDefaultFunction();
/** Prevents the default function such as the help pop-up **/
function removeDefaultFunction()
{
window.onhelp = function () { return false; }
}
/** use keydown event and trap only the F-key,
but not combinations with SHIFT/CTRL/ALT **/
$(window).bind('keydown', function(e) {
//This is the F1 key code, but NOT with SHIFT/CTRL/ALT
var keyCode = e.keyCode || e.which;
if((keyCode == 112 || e.key == 'F1') &&
!(event.altKey ||event.ctrlKey || event.shiftKey || event.metaKey))
{
// prevent code starts here:
removeDefaultFunction();
e.cancelable = true;
e.stopPropagation();
e.preventDefault();
e.returnValue = false;
// Open help window here instead of alert
alert('F1 Help key opened, ' + keyCode);
}
// Add other F-keys here:
else if((keyCode == 113 || e.key == 'F2') &&
!(event.altKey ||event.ctrlKey || event.shiftKey || event.metaKey))
{
// prevent code starts here:
removeDefaultFunction();
e.cancelable = true;
e.stopPropagation();
e.preventDefault();
e.returnValue = false;
// Do something else for F2
alert('F2 key opened, ' + keyCode);
}
});
</script>
</body>
</html>
相关文章:
- 防止默认'F1'iE11中的事件
- 正在取消IE11中的JavaScript事件
- 单击事件在替换<使用>元素在<svg>(Win7/IE11)
- RadTreeView在IE11不必要的触发事件中不起作用
- 如何处理iframe中两次或根本不触发的IE11 localStorage事件
- IE11 iFrame点击事件弹出以影响窗口
- 在 IE11 中,不会为文本框触发指针移动事件
- 在 IE11 中模拟鼠标向上事件上的输入操作
- jQuery 键下处理程序在 IE11 的 URL 字段中按 Ctrl 时接收键下事件
- 调度事件在 Chrome 中,但在 IE11 中不是
- onunload和onbeforenlad事件在IE11和IIS中未按预期工作
- 在IE11中,事件不是在javascript中触发的
- 指针事件IE11/Surface
- 带有IE11的Surface Pro 3上没有鼠标滚轮事件
- 事件.在IE11中取消使用
- 在IE11中,鼠标滚轮滚动时不会触发mouseleave事件
- 如何防止IE11和Microsoft Edge积极限制事件
- 在IE11中单击事件不触发
- windows 8.1pc的IE11中鼠标移动事件与触摸事件冲突
- IE11 Javascript更改事件不与html表单元素工作