Skip to content

Instantly share code, notes, and snippets.

@tikitikipoo
Created February 12, 2012 12:26
Show Gist options
  • Save tikitikipoo/1808259 to your computer and use it in GitHub Desktop.
Save tikitikipoo/1808259 to your computer and use it in GitHub Desktop.
Javascriptでデバイスがiosかどうか判別
// 出所:http://stackoverflow.com/questions/9038625/detect-if-device-is-ios
var iOSversion = false,
w = window,
p = navigator.platform;
if( p === 'iPad' || p === 'iPhone' || p === 'iPod' ){
!!w.history && !!w.history.pushState ? iOSversion = '4+' : iOSversion = '4-';
!!w.matchMedia ? iOSversion = '5+' : '';
}
// Another way to do it is using navigator.appVersion:
var iOSversion = false,
p = navigator.platform;
if( p === 'iPad' || p === 'iPhone' || p === 'iPod' ){
iOSversion = navigator.appVersion.split(' ')[0] || false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment