I can detect iOS 13 on iPhone but in iPad OS 13 navigator.platform
comes as MacIntel. So it is not possible to get iPad identified using below code, but it works perfectly on iPhone.
if (/iP(hone|od|ad)/.test(navigator.platform)) {
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
var version = [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
return version;
}
When we request for mobile website using the browser on iPad navigator.platform
returns as iPad and works perfectly.
Can anyone suggest a way to identify iPad running on iOS 13 and up using Javascript?
TL;DR
We can use the
navigator.standalone
param. It's non-standard and used only on iOS Safari at present:When combined with
navigator.platform === "MacIntel"
iPad's are the only devices that define this property, thereforetypeof navigator.standalone !== "undefined"
filters out Macs running Safari (touchscreen or not).I set up a CodeSandbox and manually tested on Browserstack, seems to work as expected: https://bc89h.csb.app/
Version Detection (iOS only)
I haven't tested this too extensively but should give anyone else looking a good place to start:
The above takes the version and breaks it down into major, minor and patch elements. This seems to work for iOS 12 & 13 which I ran a quick test against. The above SandBox link shows the output.