I use a web app for work, and one of the shortcuts I use often is Ctrl+M. However, I'm often typing very quickly and mistakenly hit Ctrl+N by mistake, and instead of triggering an action in my web app, I open up a new window. I would like to be able to prevent that, but I can't seem to figure out how. So far I've tried running this code every time the page loads, but it doesn't seem to do anything. (Ignore the fact that I'm using a switch for just one key, I have a few other custom Ctrl shortcuts that don't override Chrome shortcuts that are working, I just removed them for readability)
document.onkeydown = function(e)
{
if(e.ctrlKey === false)
{
return;
}
switch(e.which) {
case 78:
//just to keep from opening a new tab when merging cells
e.preventDefault();
e.stopPropagation();
break;
default:
return;
}
};