I've been experimenting with this code snippet to check if the browser is iOS 5 or newer (found on this Stack Overflow 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 newer.');
} else {
alert('This is NOT running iOS 5 or newer.');
}
It functions correctly on iOS 5 or above, but triggers the following error in other browsers:
Uncaught TypeError: Cannot read property '0' of undefined
Subsequently, all JavaScript after this specific code fails to execute.
I would appreciate any guidance on resolving this issue. Thank you.