Getting (mobile) device name from javascript

Related searches

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't do this through javascript for a web app running in a native browser - javascript generally doesn't have access to this personal identifying data.

One possible way is to use a framework like PhoneGap which may have an API to access the device name. But then, you can only deploy your web site via an app store, so this could be very limiting based on your use case.

JavaScript Device Detection. In this tutorial I explain how to…, This API is a JavaScript implementation to discover a lot of information about user's device. More specifically, you are able to detect the type of device, name of device, For example, the API can be used to route mobile users to a specific page. A button that says 'Get it on, Google Play', and if clicked. There is no reliable way to get a phone number with JavaScript without prompting the user. That is, it cannot be retrieved automatically using a browser API. It is possible inside of certain Android / iPhone application views. See discussions here: How can I get the device's phone number through JavaScript in Android?.

Your best bet is to use the user agent:


const ua = navigator.userAgent
const device = {
  iPad: /iPad/.test(ua),
  iPhone: /iPhone/.test(ua),
  Android4: /Android 4/.test(ua)

The object will allow you to write nice conditional logic such as if(device.iPad) { /* do stuff */ }

How can we get the device information using JavaScript , What I want is to get the details of device (name of device) and there are few libraries that can detect whether a device is phone, iPad, or pc. Django - detect mobile device in views; jquery toggleClass not working in mobile device; Unity mobile device 30fps locked; Limiting records synchronized to mobile device; Auto Detect Windows Mobile Device programmatically; How to access mobile device camera with javascript? How to draw mobile device edge using CSS? Googlebot-mobile doesn't look

I'm working with mobile device with embedded scanner. To be able to use some the JavaScript library of different devices and to avoid conflict with those libraries of different manufacturer (Zebra, Honeywell, Datalogic, iOs ect...) I need to come up with a way to identify each devices so I can load the proper library and this is what I came up with. Enjoy

getDeviceName: function () {
    var deviceName = '';

    var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        Datalogic: function() {
            return navigator.userAgent.match(/DL-AXIS/i);
        Bluebird: function() {
            return navigator.userAgent.match(/EF500/i);
        Honeywell: function() {
            return navigator.userAgent.match(/CT50/i);
        Zebra: function() {
            return navigator.userAgent.match(/TC70|TC55/i);
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i);
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        any: function() {
            return (isMobile.Datalogic() || isMobile.Bluebird() || isMobile.Honeywell() || isMobile.Zebra() || isMobile.BlackBerry() || isMobile.Android() || isMobile.iOS() || isMobile.Windows());

    if (isMobile.Datalogic())
        deviceName = 'Datalogic';
    else if (isMobile.Bluebird())
        deviceName = 'Bluebird';
    else if (isMobile.Honeywell())
        deviceName = 'Honeywell';
    else if (isMobile.Zebra())
        deviceName = 'Zebra';
    else if (isMobile.BlackBerry())
        deviceName = 'BlackBerry';
    else if (isMobile.iOS())
        deviceName = 'iOS';
    else if ((deviceName == '') && (isMobile.Android()))
        deviceName = 'Android';
    else if ((deviceName == '') && (isMobile.Windows()))
        deviceName = 'Windows';

    if (deviceName != '') {
        consoleLog('Devices information deviceName = ' + deviceName);
        consoleLog('Devices information any = ' + isMobile.any());
        consoleLog('navigator.userAgent = ' + navigator.userAgent);

    return deviceName;

and this is an example of how it can be used:

initializeHandheldScanners: function () {
    if (DeviceCtrl.getDeviceName() == 'Zebra')

    if (DeviceCtrl.getDeviceName() == 'Honeywell')

    if (DeviceCtrl.getDeviceName() == 'Datalogic')

You can say thanks to Cory LaViska. I did this based on his work. Here is the link if you want to know more

mobile-detect.js, var os = [ { name: 'Windows Phone', value: 'Windows Phone', version: 'OS' }, var browser = [ { name: 'Chrome', value: 'Chrome', version: 'Chrome' }, var header = [ navigator.platform, function matchItem(string, data) { var agent = header.join(' '); if ( === 'Windows' && os.version > 6) { } // Windows 8. this may not be the way to go to check whether it's a mobile-device or not but as the name of your function states it's perfect to check for touch-enabled devices. +1 from me ;-) – Kathara Jun 25 '19 at 13:55

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;


Detect device, browser and version using javascript, Detect device, browser and version using javascript. First we need a list of operating systems and their matching code names within a browser header. var os = [{ name: 'Windows Phone',

With the Media Capture and Streams API you can get access to the device camera using JavaScript. Coupled with the power of WebRTC , this enables some pretty cool applications like real-time video conferencing without the need for third-party plugins.

The Get-MobileDevice cmdlet returns identification, configuration, and status information for each mobile device. You need to be assigned permissions before you can run this cmdlet. Although this topic lists all parameters for the cmdlet, you may not have access to some parameters if they're not included in the permissions assigned to you. To find the permissions required to run any cmdlet or

Implementing mobile-detect.js is very easy. Just import the library to your page, then pass the userAgent string to the constructor. var detector = new MobileDetect(window.navigator.userAgent) var detector = new MobileDetect (window.navigator.userAgent) var detector = new MobileDetect (window.navigator.userAgent) From the mobile-detect object, you can use various methods to retrieve the information like this.

  • depends on which browser the mobile device is running but do you want to know if it is an iphone or android device or which name exactly do you need ?
  • The only thing you can get is User-Agent
  • Here is a link to use WURFL.js, it's free…