Skip to content

Instantly share code, notes, and snippets.

@mislav
Created April 4, 2010 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mislav/355625 to your computer and use it in GitHub Desktop.
Save mislav/355625 to your computer and use it in GitHub Desktop.
Detect zoom factor on Mobile Safari
/* tested on the iPad and iPhone */
function getZoomFactor() {
var deviceWidth, landscape = Math.abs(window.orientation) == 90
// workaround for strange screen.height on the iPhone (v3.1.3)
if (window.screen.width == 320) deviceWidth = landscape ? 480 : 320
else deviceWidth = window.screen[landscape ? "height" : "width"]
return deviceWidth / window.innerWidth
}
@gjcourt
Copy link

gjcourt commented Oct 29, 2010

another way to do this http://gist.github.com/653079

@mislav
Copy link
Author

mislav commented Oct 29, 2010

wow! that looks much simpler

@yairEO
Copy link

yairEO commented Sep 2, 2017

what are those magic numbers 480 & 320... seems suspiciously magical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment