Skip to content

Instantly share code, notes, and snippets.

@VARGA-Peter
Forked from ngoclt/checkVersion.js
Last active May 1, 2021 14:16
Show Gist options
  • Save VARGA-Peter/12b8ded2136ac4e7b7bef6dd39d46a73 to your computer and use it in GitHub Desktop.
Save VARGA-Peter/12b8ded2136ac4e7b7bef6dd39d46a73 to your computer and use it in GitHub Desktop.
Check iOS version with Javascript
/**
* Returns the iOS version as string. For example 14.4.2 or 13.2.3.
* If the browser is not running under iOS "undefined" is returned.
*/
function iOsGetVersion()
{
const agentName = window.navigator.userAgent;
const matchingArray = agentName.match(/(iPhone|iPad).+ ([0-9_]+) .+/);
if( matchingArray ) {
return matchingArray [2].replaceAll( '_', '.' );
}
return undefined;
}
@VARGA-Peter
Copy link
Author

The original version doesn't work anymore. Test with lot of user agents.

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