Command+N not working in Chrome #172

Closed
jeremypbeasley opened this Issue Nov 13, 2013 · 3 comments

Projects

None yet

2 participants

@jeremypbeasley

Not sure why but this command is not working at all in Chrome. Works perfectly in Safari and Firefox with the below code.

Any help?

Mousetrap.bind(['command+n'], function(e) {
if (e.preventDefault) {
e.preventDefault();
} else {
// internet explorer
e.returnValue = false;
}
$( "#settings" ).toggle();
});

@ccampbell
Owner

This is because command+n in Chrome is the browser default for opening a new window. The Chrome UI team probably decided that this behavior shouldn't be allowed to be overridden. The same thing happens with command+shift+n (new incognito window) and command+t (new tab).

There is nothing I can do about this. You could try filing a bug at https://code.google.com/p/chromium/issues/list, but I'm not sure it is something they will change. It is not really a good practice to overwrite the default browser behaviors anyway. Perhaps try something like ctrl+n instead?

@ccampbell ccampbell closed this Nov 14, 2013
@jeremypbeasley

I totally get it and I would say in general it would not be a good practice but in the case of my note taking writing web app, the argument could be that it's justified. Thanks for confirming though!

@ccampbell
Owner

Ya I mean Chrome definitely takes a different stance here than the other browsers so feel free to open a ticket with them about it. You can test by just doing

document.addEventListener('keydown', function(e) {
    console.log(e);
}, false);

And you will see when you press command+n nothing gets logged. So basically it doesn't fire any event at all.

If you do open a ticket please comment on this one with a link. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment