Is there a way to get the name of a mobile device (e.g. "John's iPhone" ) using javascript?
Maybe I wasn't very clear... what I meant is not whether it's an iPhone, iPad etc. but the "device name" - for example it can be "John's iPhone".
Is there a way to get the name of a mobile device (e.g. "John's iPhone" ) using javascript?
Maybe I wasn't very clear... what I meant is not whether it's an iPhone, iPad etc. but the "device name" - for example it can be "John's iPhone".
You can use this snippet:
const getUA = () => {
let device = "Unknown";
const ua = {
"Generic Linux": /Linux/i,
"Android": /Android/i,
"BlackBerry": /BlackBerry/i,
"Bluebird": /EF500/i,
"Chrome OS": /CrOS/i,
"Datalogic": /DL-AXIS/i,
"Honeywell": /CT50/i,
"iPad": /iPad/i,
"iPhone": /iPhone/i,
"iPod": /iPod/i,
"macOS": /Macintosh/i,
"Windows": /IEMobile|Windows/i,
"Zebra": /TC70|TC55/i,
}
Object.keys(ua).map(v => navigator.userAgent.match(ua[v]) && (device = v));
return device;
}
console.log(getUA());