I'm trying to use the following script to detect whether the browser is iOS 5 or higher (from this SO thread Detect iOS version less than 5 with JavaScript).
function iOSversion() {
if (/iP(hone|od|ad)/.test(navigator.platform)) {
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 5 or later.');
} else {
alert('This is NOT running iOS 5 or later.');
}
It works in iOS 5 or later as it should, but in any other browser it produces the following error:
Uncaught TypeError: Cannot read property '0' of undefined
And then all JavaScript below this script fails.
Please can someone advise how I can fix this?? Thank you.