Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
How to know device-type from JS Navigator object?

Is there a way to know device type - ex: mobile, tablet from Navigator API - https://developer.mozilla.org/en-US/docs/Web/API/Navigator?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In a secure context, you can use navigator.userAgentData, which provides a NavigatorUAData object, which has some useful information about the user agent (browser), including a mobile flag. The getHighEntropyValues method returns a promise which will be fulfilled with more detailed information (if the user allows it) or rejected (if not, or the browser doesn't offer high-entropy values).

For platforms that don't support userAgentData (yet), you can fall back to parsing the userAgent string, but beware that the userAgent string is notoriously unreliable and easily spoofed.

about 4 years ago · Juan Pablo Isaza Report

0

You can use the following function:

getDeviceType() {
        const ua = navigator.userAgent;
        const tabletRegex = /(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i;
        const mobRegex = /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/;

        if (tabletRegex.test(ua)) return "tablet";
        if (mobRegex.test(ua)) return "mobile";
        return "desktop";
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!