Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1cbbac9

Browse files
authored
Create userOS.js
1 parent df37529 commit 1cbbac9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎js-coding-technique/userOS.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function getUserOS() {
2+
let device = 'Unknown';
3+
const ua = {
4+
'Generic Linux': /Linux/i,
5+
Android: /Android/i,
6+
BlackBerry: /BlackBerry/i,
7+
Bluebird: /EF500/i,
8+
'Chrome OS': /CrOS/i,
9+
Datalogic: /DL-AXIS/i,
10+
Honeywell: /CT50/i,
11+
iPad: /iPad/i,
12+
iPhone: /iPhone/i,
13+
iPod: /iPod/i,
14+
macOS: /Macintosh/i,
15+
Windows: /IEMobile|Windows/i,
16+
Zebra: /TC70|TC55/i,
17+
};
18+
Object.keys(ua).map((v) => navigator.userAgent.match(ua[v]) && (device = v));
19+
return device;
20+
}
21+
22+
console.log({OS: getUserOS()});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /