Override CMD+N or CTRL+N shortcuts in javascript/jquery? -


i'm working on web app , want override ctrl+n (windows) cmd+n (mac) shortcuts don't open new windows. want custom events trigger.

$(window).bind( 'keydown', function(e) {     if(e.ctrlkey && e.keycode === 'n'.charcodeat(0)){         e.preventdefault();         // custom trigger     } }); 

thanks help!

plz try 1

<script> window.addeventlistener('keyup', function(e) { if (e.keycode === keycode.key_return) {     console.log('it return key.'); } else {     console.log('it 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> 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -