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

336
Visualizações
How to check if browser has pdf viewer or not in javascript

I need to check if the browser has ability to show pdf in iframe.

I was trying to simple check mimeTypes or plugins but now in Firefox on mac, it doesn't seem to be working fine, it shows empty array.

function isPDFSupported(): boolean {
  let hasPDFViewer = false;
  try {
    const pdf =
      navigator.mimeTypes && (navigator.mimeTypes as any)['application/pdf']
        ? (navigator.mimeTypes as any)['application/pdf'].enabledPlugin
        : 0;
    if (pdf) hasPDFViewer = true;
  } catch (e) {
    if ((navigator.mimeTypes as any)['application/pdf'] != null) hasPDFViewer = true;
  }

  return hasPDFViewer;
}

also check the developer.mozilla page for mimeTypes https://developer.mozilla.org/en-US/docs/Web/API/Navigator/mimeTypes and it shows that mimeTypes and plugin is deprecated...

Do you know some other alternatives? or just simply do if IE download pdf and in other cases try to show pdf?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I recently came across the same challenge and found a way to check for a PDF viewer plugin.

As explained in the Mozilla documentation, the navigator.plugins property returns a PluginArray object, which lists all of the plugins that are installed in the application.

PDF inline viewing plugins will contain "PDF viewer" in the plugin name, e.g. "Chrome PDF Viewer" or "Microsoft Edge PDF Viewer". So you can check if any of the plugins contain this string as follows:

if ('PDF Viewer' in navigator.plugins) {
  // your code
}

This worked well for me. However, I need to point out that this method is deprecated so I'm not sure how long it will still be supported.

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