Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable browser zoom on certain elements in Firefox

Is it possible to disable the in-browser, full-page zoom in Firefox (activated by Ctrl +) for a webpage? How about for certain elements in a webpage? I just notice that sometimes elements look really weird when they are zoomed, and it might be nice to just disable the zooming completely for those elements.

Note: I know there a few ways to find the zoom level, but this is really wanting to actively work around it (which might not be a good idea anyway).

like image 474
Jonathan Morgan Avatar asked Jan 02 '11 14:01

Jonathan Morgan


1 Answers

Using information gathered largely through this question: Catch browser's "zoom" event in JavaScript

I've been playing around with attempting to track browser zoom for the last day or so, and this is about as close as you can get without an onZoom standard event that you can kill.

document.observe('keydown', function (ev) {
  var key, keys = ['0'];
  var isApple = (navigator.userAgent.indexOf('Mac') > -1), isCmmd, isCtrl;
  if (window.event)
  {
    key = window.event.keyCode;
    isCtrl = window.event.ctrlKey ? true : false;
    isCmmd = window.event.metaKey ? true : false;
  } else {
    key = e.which;
    isCtrl = ev.ctrlKey ? true : false;
    isCmmd = ev.metaKey ? true : false;
  }
  if (isCtrl || (isCmmd && isApple)) {
    switch (key) {
      case 48: // 0
        // do not stop, or user could get stuck
        break;
      case 187: // +
      case 189: // -
        ev.stop()
        break;
      default:
        break;
    }
  }
});

Unfortunately, and I've been playing with this for a while now, and there isn't any surefire way to really disable it. The zoom options are still available through main application menus, so until a real method of tracking zoom (including after page reloads, which mostly impossible right now, and, besides, webkit exhibits some odd behavior when you attempt to track zoom).

Although many people would like to keep browser zoom more hidden, I can personally see the possible benefits of being able to observe zoom separately from resize, as they are mostly indistinguishable at this point (and that's if for no other reason at all).

like image 116
Adam Eberlin Avatar answered Sep 22 '22 18:09

Adam Eberlin