Created
October 5, 2012 14:09
-
-
Save cemerson/3839984 to your computer and use it in GitHub Desktop.
JavaScript: Detect iPhone/iPad Types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pixelRatio = window.devicePixelRatio || 1; | |
var viewport = { | |
width: window.innerWidth, | |
height: window.innerHeight | |
}; | |
var screen = { | |
width: window.screen.availWidth * pixelRatio, | |
height: window.screen.availHeight * pixelRatio | |
}; | |
var iPhone = /iPhone/i.test(navigator.userAgent); | |
var iPhone4 = (iPhone && pixelRatio == 2); | |
var iPhone5 = /iPhone OS 5_0/i.test(navigator.userAgent); // ? | |
var iPad = /iPad/i.test(navigator.userAgent); | |
var android = /android/i.test(navigator.userAgent); | |
var webos = /hpwos/i.test(navigator.userAgent); | |
var iOS = iPhone || iPad; | |
var mobile = iOS || android || webos; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment