Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event binding Ctrl-Shift-N in Chrome

I'm using to jQuery.hotkeys to bind keyboard events.

I'm trying to bind Ctrl+Shift+N

$(document).bind('keydown', 'ctrl+shift+n', function(e) {
    e.preventDefault();
    alert('Ctrl+Shift+N');
    return false;
});

The above is not working. Any ideas?

like image 272
Timothy Clemans Avatar asked Apr 26 '26 11:04

Timothy Clemans


1 Answers

Chrome doesn't let you take over some shortcuts.

If you use the following code http://jsfiddle.net/rNkmA/1/

$(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;
    }
});​

You'll see that the handler never gets called in Chrome

I suggest you use a shortcut that is not preassigned to chrome like alt+shift+n. That will work in FF, IE, Safari and Chrome (does anybody ever test for Opera?)

like image 67
Juan Mendes Avatar answered Apr 29 '26 00:04

Juan Mendes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!