Skip to content

Instantly share code, notes, and snippets.

@jordandobson
Created April 13, 2010 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jordandobson/365095 to your computer and use it in GitHub Desktop.
Save jordandobson/365095 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
var appVer = navigator.appVersion;
var searchVersion = /\s(\d)_\d/;
var searchDevice = /\s[(](\w+\s?\w*)[;]\s/;
var isIPhone = false;
var isIPad = false;
if (searchVersion.exec(appVer) && searchDevice.exec(appVer)){
var deviceVersion = searchVersion.exec(appVer)[1];
if ("iPhone" == searchDevice.exec(appVer)[1]){ isIPhone = deviceVersion; }
if ("iPhone Simulator" == searchDevice.exec(appVer)[1]){ isIPhone = deviceVersion; }
if ("iPad" == searchDevice.exec(appVer)[1]){ isIPad = deviceVersion; }
}
if(isIPad){ alert("iPad Version: " + isIPad ); }
if(isIPhone){ alert("iPhone Version: " + isIPhone); }
</script>
@jordandobson
Copy link
Author

This should detect if you have an iPad or iPhone and store the version number in either the isIPhone or isIPad variable.

You can see an example of this script here: http://jordandobson.com/_expirements/iphone-ipad/version_detect.html

NOTE: If you don't use an iPhone or iPad to load the page you won't get an alert.

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