在Firefox和Chrome中重写快捷键 [英] Overriding shortcut keys in firefox and chrome
问题描述
我有一个脚本,应该打开一个网页的一部分,并保存更改Ctrl + n和Ctrl + s repectivly我得到它在IE浏览器中工作,但似乎并没有在Firefox和铬。任何想法?
我的搭车功能。
function prevent (e)
{
try {e.stopPropagation();} catch(ex){}
try {e.preventDefault()} catch(ex){}
try { if(e.preventDefault)
e.preventDefault();
else {
e.cancelBubble = true;
e.returnValue = false;
e.keyCode = 0;
}} catch(ex){}
}
我看到了同样的问题。有些浏览器不允许你捕捉某些快捷方式。看看这个 https://stackoverflow.com/a/7296303/1366887
一些组合键在Chrome 4中被滥用,而在Chrome 3中则没有。请看这里: https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-bugs/Ntc1byZXHfU
这里是Javascript:
$(window).keydown (event(event){
if(event.ctrlKey& event.keyCode == 84){
console.log(Hey!Ctrl + T event captured!);
event.preventDefault();
}
if(event.ctrlKey&& event.keyCode == 83){
console.log(Hey!Ctrl + S event captured! );
event.preventDefault();
}
});
我曾经使用过这么多次,
下面是另外一个可以查看的资源: http://unixpapa.com/js/key.html
没有Jquery:
< (e.ctrlKey& e.keyCode =='S'.charCodeAt(0)){
($ c $) e.preventDefault();
//您的储蓄码
code $ $ $ $ $ $ $ $ $ $ $ $ $它的 JSFIDDLE 正在工作。
I have a script that is supposed to open a section of a web page and save changes on Ctrl + n and Ctrl + s repectivly I got it working in IE but it doesn't seem to work in firefox and chrome. Any ideas?
My over ride function.
function prevent(e)
{
try{e.stopPropagation();}catch(ex){}
try{e.preventDefault()}catch(ex){}
try{if (e.preventDefault)
e.preventDefault();
else {
e.cancelBubble = true;
e.returnValue = false;
e.keyCode = 0;
}} catch(ex){}
}
I have seen the same issue. Some browsers will not allow you to capture certain shortcuts. Look at this https://stackoverflow.com/a/7296303/1366887
Some key combinations are resticted in Chrome 4, but not in Chrome 3. Look here: https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-bugs/Ntc1byZXHfU
Here is the Javascript:
$(window).keydown(function(event) {
if(event.ctrlKey && event.keyCode == 84) {
console.log("Hey! Ctrl+T event captured!");
event.preventDefault();
}
if(event.ctrlKey && event.keyCode == 83) {
console.log("Hey! Ctrl+S event captured!");
event.preventDefault();
}
});
I have used this numerous times, and it has worked greatly.
Here is another rescource you can take a look at: http://unixpapa.com/js/key.html
Without Jquery:
onkeydown = function(e){
if(e.ctrlKey && e.keyCode == 'S'.charCodeAt(0)){
e.preventDefault();
//your saving code
}
}
Here is a JSFIDDLE of it working.
这篇关于在Firefox和Chrome中重写快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!