Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save coltondick/339e689c0a0e9ef61a4b27147aaa83bb to your computer and use it in GitHub Desktop.
Save coltondick/339e689c0a0e9ef61a4b27147aaa83bb to your computer and use it in GitHub Desktop.
Detect iOS Version with jQuery Javascript
<h1>Detect iOS Version from V2 upwards. Body will fill with green background if iOS is detected</h1>
$(document).ready(function() {
function iOSversion() {
if (/iP(hone|od|ad)/.test(navigator.platform)) {
// supports iOS 2.0 and later: <https://bit.ly/TJjs1V>
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
}
}
ver = iOSversion();
if (ver[0] >= 5) {
alert('This is running iOS '+ver);
/*$('body').addClass('iOS-tagged');
*/}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
body{ margin: 0;}
.iOS-tagged {
background:green;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment