1

I'm working on a web app and I want to override CTRL+N (windows) CMD+N (mac) shortcuts so they don't open a new windows. I want custom events to trigger.

$(window).bind( 'keydown', function(e) {
    if(e.ctrlKey && e.keyCode === 'N'.charCodeAt(0)){
        e.preventDefault();
        // custom trigger
    }
});

Thanks for help!

Milan Chheda
  • 8,159
  • 3
  • 20
  • 35
lucian24
  • 45
  • 6

1 Answers1

-1

Plz try this one

<script>
window.addEventListener('keyup', function(e) {
if (e.keyCode === KeyCode.KEY_RETURN) {
    console.log('It was the Return key.');
} else {
    console.log('It was any other key.');
}
});
<script>

OR

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script>
    var pKey;
    $(function () {
        $(window).keydown(function (e) {
            if (e.which == 17) {
                pKey = e.keyCode;
            }
            else {
                if (pKey == 17 && e.keyCode == 78) {
                    e.preventDefault();
                    console.log(e);
                }
            }
        });
    });
</script>
</head>
<body>

 <div class="container">
   <h2>Well</h2>

   <div class="well">Hello G...</div>
 </div>

 </body>
 </html>
Ravi Kharinta
  • 69
  • 1
  • 8