Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda