1

It is possible to catch Ctrl + + / Ctrl + - events on Firefox with :

window.onkeydown = function(event)
{
  if(event.ctrlKey && event.keyCode == 61)
        CtrlPlus();
  if(event.ctrlKey && event.keyCode == 169) // or == 54, depends on keyboard layout
        CtrlMinus();
};

But in Chrome, it doesn't work : Ctrl + + is always linked at Chrome's internal "Zoom +" command.

How is it possible to override Chrome's Ctrl + + ?

Basj
  • 41,386
  • 99
  • 383
  • 673
  • Did you try `event.preventDefault();`? https://developer.mozilla.org/en/docs/Web/API/event.preventDefault – Prusse Sep 19 '14 at 16:23
  • @Prusse it works! (I had tested this before, and I thought it didn't work, I maybe made a mistake...) If you copy/paste as an answer, I'll accept it ! – Basj Sep 19 '14 at 16:44

1 Answers1

1

Did you try event.preventDefault();?

https://developer.mozilla.org/en/docs/Web/API/event.preventDefault

Prusse
  • 4,287
  • 2
  • 24
  • 29
  • now it doesn't work with Safari..... Any idea @Prusse : http://stackoverflow.com/questions/26002958/event-preventdefault-works-on-chrome-firefox-but-not-safari?noredirect=1#comment40723240_26002958 – Basj Sep 24 '14 at 13:59
  • Try to also `return false` like suggested in this other answer http://stackoverflow.com/a/6186102/783219 – Prusse Sep 25 '14 at 17:58
  • It may offer some light reading http://stackoverflow.com/q/1357118/783219, this one is a thread about jquery, but some info may be helpful. You may ALSO try `stopPropagation`. – Prusse Sep 25 '14 at 18:05