0

I'm trying to bind Ctrl+shift+N keydown event form Chrome browser, but it is not working. Following is the snippet of code:

$(document).bind('keydown', function(e) {
    console.log(e.which);
    console.log(e.ctrlKey);
    console.log(e.shiftKey);
    if (e.ctrlKey && e.shiftKey && e.which === 78) {
        e.preventDefault();
        console.log('Ctrl+Shift+N');
        return false;
    }
});

On the other browsers its working fine, since Chrome browser has already assigned this shortcut for "New incognito window". So is there any way to prevent this default behavior or catch this event ?

Sagar Ganesh
  • 2,454
  • 3
  • 20
  • 32
  • Are you trying to stop people opening an incognito window? – Rory McCrossan Jun 08 '16 at 06:46
  • Don't override custom key-bindings, *regardless of your intentions*; it does nothing but annoy users that're used to, and wish to use, those key-bindings. – David Thomas Jun 08 '16 at 06:46
  • @DavidThomas: Oh, I don't know. I'm pretty happy that Google Docs overrides Ctrl+U to mean underline rather than view source. – T.J. Crowder Jun 08 '16 at 06:49
  • No, :) im not trying to stop incognito browsing. As there is requirement of that. – Sagar Ganesh Jun 08 '16 at 06:51
  • @T.J.Crowder: true, but that's done sensibly to reflect the key-bindings used in word processors, though I accept that it's something of a special case. If someone overrode the Ctrl+1, Ctrl+2 key bindings for tab-switching I would, personally, be annoyed. – David Thomas Jun 08 '16 at 06:55
  • @DavidThomas: The point is it depends on the key binding ("view source" just isn't as useful/important as tab switching) and the use case of the web page/app. Perhaps if Ctrl+1 were sufficiently important in the web app, you'd accept it. (Or perhaps not.) (Bad news, btw: Chrome lets the page intercept it, unlike Ctrl+N or Ctrl+Shift+N. :-) ) – T.J. Crowder Jun 08 '16 at 06:59
  • @DavidThomas: Thank you for the Ctrl+1 and such reminder, btw! – T.J. Crowder Jun 08 '16 at 07:00

0 Answers0