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

334
Views
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 answers
Answer question

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 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!