Created
July 14, 2021 17:35
-
-
Save coltondick/339e689c0a0e9ef61a4b27147aaa83bb to your computer and use it in GitHub Desktop.
Detect iOS Version with jQuery Javascript
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
<h1>Detect iOS Version from V2 upwards. Body will fill with green background if iOS is detected</h1> |
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
$(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'); | |
*/} | |
}); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
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
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