1

I am using ctrl + charCode**s in order to delete a row from the listing page which is working fine on firefox but when I tested it on **Chrome, the event.preventDefault() couldn't stop the browser based function to come up

function showkey(e){
     if(e.ctrlKey && e.charCode == 100){  
        e.preventDefault();
        //delete code // }

<body onkeypress="showkey(event);">

2 Answers2

0

You can acheive with jQuery. Include jQuery library

$(document).bind('keydown', function(e) {
  if(e.ctrlKey && (e.which == 100)) {
    e.preventDefault();
    return false;
  }
});

This works :)

Khaleel
  • 1,212
  • 2
  • 16
  • 34
0

look this answer Override the bookmark shortcut (Ctrl+D) function in Chrome

working solution just tested on this page

document.addEventListener('keydown', function(event) {
  if (event.ctrlKey && String.fromCharCode(event.keyCode) === 'D') {
    console.log("you pressed ctrl-D");
    event.preventDefault();
    event.stopPropagation();
  }
}, true);
Community
  • 1
  • 1
Panoptik
  • 1,094
  • 1
  • 16
  • 23