2012-04-02 102 views
2

有没有什么办法可以陷阱ctrl + n chrome中的键(通过使用javascript,jquery或任何插件)?我需要分配CTRL +ñ+进入关键特定的任务,但只要我按下CTRL +ñ,铬打开一个新窗口。我能够陷阱CTRL +ñ在Firefox中使用:chrome中的ctrl + n组合键

event.preventDefault() 

,但它不是在铬工作。

+0

*“我能够捕获CTRL + N在Firefox中使用event.preventDefault(),但它不是在铬工作。” *总是最好的展现你的代码,但它是在这种情况下,学术:您可以不要这样做,看看userD指出的另一个问题。 – 2012-04-02 06:40:21

+2

可能的重复http://stackoverflow.com/questions/632062/ways-to-detect-ctrl-n-or-when-a-user-opens-a-new-window – Dhiraj 2012-04-02 06:40:50

+0

了解它...它不可能在铬4现在。 – user1304683 2012-04-02 09:50:29

回答

0

这可能适用于您的问题。

// defining flags 
var isCtrl = false; 
var isShift = false; 
$(document).ready(function() { 
    // action on key up 
    $(document).keyup(function (e) { 
     if (e.which == 17) { 
      isCtrl = false; 
     } 
     if (e.which == 16) { 
      isShift = false; 
     } 
    }); 


    $(document).keydown(function (e) { 
     if (e.which == 17) { 
      isCtrl = true; 
     } 
     if (e.which == 16) { 
      isShift = true; 
     } 

if ((e.which == 110 || e.which == 78) && isCtrl) { 
      e.preventDefault(true); 
} 
});