Joda Maki
Joda Maki

Reputation: 5869

Detect Zoom in Firefox

I want to detect if the browser is zoomed in or out (don't really care to know the value, but I assume it will need to be found anyway in the decision process). I have read a lot of other SO posts on the topic, but none of the solutions given work on FF (although there is an IE7/8 and chrome solution).

Oh, and I can't use flash, so the flash solution is out of the question.

Edit: And I must be able to detect this on the initial page load

Upvotes: 12

Views: 4286

Answers (5)

Brian Webster
Brian Webster

Reputation: 30855

With modern versions of FireFox, you can now do the following:

DPR = window.devicePixelRatio;
if ( DPR <= 0.999 || DPR >= 1.001 ){
   // User has zoomed in or zoomed out
}

Upvotes: 7

ripper234
ripper234

Reputation: 230038

I suggest you look at this generic question. And possibly close your own as a duplicate (not voting to do this myself, since it's not "an exact dup".

Upvotes: 1

Litek
Litek

Reputation: 4888

If by zoom you mean that the user pressed ctrl/cmd+[plus] and not css transformation you can detect computed font-size. Just checked in FF 4.0.1/Mac and it worked for me. To detect computed font-size I used code from this question: Get computed font size for DOM element in JS .

The value changed after zooming. You need to know what the font-size of a certain element should be (as set in css) and compare it with what it really is.

Upvotes: 2

SpliFF
SpliFF

Reputation: 38976

Maybe instead of detecting the zoom you could detect the error.

For example if your layout expects an elements' offset to be at 100,200 and a query shows it's at 300,450 you'll know it's in the wrong place and you can apply your fixup/workaround.

This has the added benefit that if the zoom issue is fixed in a future version of the browser you won't be applying your fix needlessly or incorrectly.

Upvotes: 0

AjayR
AjayR

Reputation: 4179

Did you try to detect the resolution, which may help you to detect the zoom.

Upvotes: 0

Related Questions