2

For a HTML game I want to disable the normal zooming functionality in Chrome.

This question talks about how to use the viewport meta tag to disable zoom in Chrome on Android but this does not seem to work in normal desktop chrome.

Community
  • 1
  • 1
Patrick Klug
  • 13,181
  • 13
  • 70
  • 114
  • I'm pretty positive you can't disable zooming in Chrome; a better question is why you would want to though. – Explosion Pills Mar 20 '13 at 02:25
  • it's common for a game to assume a fixed zoom level for the viewport, isn't it? I have many layers which make up the game UI such as different canvas, popups, status bars etc. Most of these don't stick together well if the user zooms in our out. the game is also a single-page app which is always full screen. zooming is of little use. – Patrick Klug Mar 20 '13 at 02:40
  • 1
    I'm reasonably sure as well that you would not be able to prevent a user from zooming on a desktop browser. If you really need it I think your best bet could be to try and detect if the user tries to zoom and tell them to fix it before they continue. This question has some details on trying to detect the zoom. http://stackoverflow.com/questions/995914/catch-browsers-zoom-event-in-javascript – Dracs Mar 20 '13 at 02:47
  • 1
    I don't think you can do much to prevent the zooming without changing a lot on the presentation side. One silly thing you can do is to set changes for important presentation styles (possibly width, height, font size, positioning etc.) via JavaScript to slightly different values and set a transition on the elements that takes a tremendously long time. I think it's a bug in Chrome/Webkit, but as long as it's animating via the transition, zooming won't affect it. This is obviously not totally practical: http://jsfiddle.net/ExplosionPIlls/RfFpK/ – Explosion Pills Mar 20 '13 at 02:48
  • I wonder if I could just counteract any zoom level. If I can detect what the zoom level is I could just zoom the content to end up at 100% again? If the cycle is fast enough it might even look as if zooming is disabled. – Patrick Klug Mar 20 '13 at 02:55
  • @ExplosionPills interesting hack :) – Patrick Klug Mar 20 '13 at 03:11

1 Answers1

0

While this doesn't answer my original question (I asked about a page displayed in Chrome) I just wanted to document that Chromium (the OSS behind Chrome) seems to have a flag which controls whether it will support the viewport meta tag:

// Enables the use of the viewport meta tag, which allows
// pages to control aspects of their own layout. This also turns on touch-screen
// pinch gestures.
const char kEnableViewport[]                = "enable-viewport";

(soure: http://src.chromium.org/svn/trunk/src/content/public/common/content_switches.cc)

So, if packaging the game into its own chromium instance is an option (which in my case is likely), zooming could be disabled via the viewport meta tag.

Patrick Klug
  • 13,181
  • 13
  • 70
  • 114
  • Nice find. But if you were building your own Chromium instance, Couldn't you just disable the zoom in the code instead? – Dracs Mar 20 '13 at 03:14
  • 1
    well sure, but packaging in its own chromium instance and actually tweaking that instance's behaviour require different skills. why change something yourself if there's a ready made configuration option. – Patrick Klug Mar 20 '13 at 03:16