Skip to content

Commit 6b1c680

Browse files
committed
Add new guide: detecting iPad
1 parent aedfd1b commit 6b1c680

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

docs/.vitepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ export default defineConfig({
216216
text: 'Guides',
217217
collapsed: false,
218218
items: [
219+
{ text: 'How to Detect iPad', link: '/guides/how-to-detect-ipad-using-javascript' },
219220
{ text: 'How to Detect iOS ≥ 26', link: '/guides/how-to-detect-ios-26-using-javascript' },
220221
{ text: 'How to Detect macOS > 10.15.7', link: '/guides/how-to-detect-macos-10157-using-javascript' },
221222
{ text: 'How to Detect Windows 11', link: '/guides/how-to-detect-windows-11-using-javascript' },

docs/api/submodules/helpers/is-frozen-ua.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Chrome/[majorVersion].0.0.0 [deviceCompat] Safari/537.36
1212
| Token | Possible values |
1313
| ------ | ---------------- |
1414
| `[unifiedPlatform]` | <p>Desktop:</p><ul><li>`Windows NT 10.0; Win64; x64`</li><li>`Macintosh; Intel Mac OS X 10_15_7`</li><li>`X11; Linux x86_64`</li><li>`X11; CrOS x86_64 14541.0.0`</li><li>`Fuchsia`</li></ul><p>Mobile:</p><ul><li>`Linux; Android 10; K`</li></ul> |
15-
| `[deviceCompat]` | <ul><li>(empty) — for tablets/desktops</li><li>`Mobile` — for mobile devices</li></ul> |
15+
| `[deviceCompat]` | <p>Desktop/Tablet:</p><ul><li>'' (empty)</li></ul><p>Mobile:</p><ul><li>`Mobile`</li></ul> |
1616

1717
::: tip
1818
Learn how to identify the real device behind a reduced user-agent [here](/guides/how-to-identify-android-k-device)

docs/guides/how-to-detect-ios-26-using-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Starting with Safari on iOS 26, you can no longer rely on the User-Agent string to determine iOS version. This issue is because WebKit (the underlying engine developed by Apple that powers all browsers on iOS) now freezes the reported iOS version at `18.6`:
44

5-
- [Safari on iOS/iPadOS/visionOS 26: "user agent string no longer lists the current version of the operating system"](https://webkit.org/blog/17333/webkit-features-in-safari-26-0/#update-to-ua-string) *—Webkit Blog*
5+
- [Safari on iOS/iPadOS/visionOS 26: "user agent string no longer lists the current version of the operating system"🡥](https://webkit.org/blog/17333/webkit-features-in-safari-26-0/#update-to-ua-string) *—Webkit Blog*
66

77
::: info
88
An example of User-Agent string on iOS 18.6:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# How to Detect iPad using JavaScript
2+
3+
iPads used to have a very clear user-agent string that included the keyword `iPad`, for example:
4+
5+
`Mozilla/5.0 (iPad; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4`
6+
7+
However, starting from iPadOS 13, Apple forces Safari to use desktop mode by default. This makes Safari on iPad started identifying itself as a desktop device (`Macintosh`) instead of `iPad`, like:
8+
9+
`Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15`
10+
11+
This makes user-agent detection not reliable when detecting iPad. As a workaround, you can use [`withFeatureCheck()`](/api/main/idata/with-feature-check) method to also detect for some iPad-specific browser features in addition to the usual user-agent detection.
12+
13+
## Code Example
14+
15+
### User-Agent Detection Only
16+
17+
```js [user-agent-detect.js]
18+
import { UAParser } from 'ua-parser-js';
19+
20+
const parser = new UAParser();
21+
const device = parser.getDevice();
22+
23+
if (device.is('iPad')) {
24+
console.log("Hi, looks like you're using an iPad!");
25+
}
26+
```
27+
28+
### User-Agent Detection + Feature Detection
29+
30+
```js [with-feature-detect.js]
31+
import { UAParser } from 'ua-parser-js';
32+
33+
const parser = new UAParser();
34+
const device = await parser.getDevice().withFeatureCheck();
35+
36+
if (device.is('iPad')) {
37+
console.log("Hi, looks like you're using an iPad");
38+
}
39+
```
40+
41+
## References
42+
43+
* [iPadOS brings breaking changes for developers🡥](https://docs.getupdraft.com/ios/ipados) *—Updraft Blog*
44+
* [`withFeatureCheck()`](/api/main/idata/with-feature-check)

0 commit comments

Comments
 (0)