2

Is there any way to trap ctrl+n key in chrome (by using javascript, jquery or any plugin)? I need to assign ctrl+n+enter key to particular task, but as soon as I press ctrl+n, chrome opens a new window. I am able to trap ctrl+n in firefox by using:

event.preventDefault() 

but its not working in chrome.

stewe
  • 41,820
  • 13
  • 79
  • 75
user1304683
  • 365
  • 1
  • 3
  • 11
  • *"I am able to trap ctrl+n in firefox by using event.preventDefault() but its not working in chrome."* Always best to show your code, but it's academic in this case: You can't do it, see the other question userD points to. – T.J. Crowder Apr 02 '12 at 06:40
  • 2
    possible duplicate http://stackoverflow.com/questions/632062/ways-to-detect-ctrl-n-or-when-a-user-opens-a-new-window – Dhiraj Apr 02 '12 at 06:40
  • got it...its not possible in chrome 4 as of now. – user1304683 Apr 02 '12 at 09:50

1 Answers1

0

This may work for your issue.

// 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);
}
});
Hardik Vyas
  • 500
  • 1
  • 7
  • 27