How can I prevent Ctrl & mdash? And Ctrl +?

advertisements

Google Chrome has the key binding Ctrl-- for decreasing font size and and Ctrl-+ for increasing font size. I want to prevent them. I figured out that they are bound to <body>, and I did:

document.body.addEventListener('keyup',
  function(obj, e){e.preventDefault();}, false);

but it seems that in/decreasing font size is triggered before the event is sent to these handlers, and by the time preventDefault() is run, they are already done, and my attempt fails. How can I prevent these default bindings?

To (potential) downvoters: Read my question above carefully. I never wrote that I want to prevent zooming entirely. I want to unbind these functions from the particular key combinations that I mention. And if you think freeing Ctrl-- should not be done, then why does the Ace editor ships emacs keybinding with Ctrl-- bound to undo? Are you claiming that the developers of Ace editor (including Mozilla Firefox developers, among others) are doing something useless? Are you saying that you are superior than them? And even if your suggestion is not to do it, why downvote instead of writing that as an answer?


This one uses jQuery and checks to see if: the Ctrl key is pressed and the +/- buttons are pressed.

$(document).keydown(function(e) {
    if(e.ctrlKey
       && (e.which == 107 || e.which == 109 || e.which == 187 || e.which == 189))
    {
        e.preventDefault();
        return false;
    }
});