Women in Technology

Hear us Roar



Article:
  Plug-In Detection with JavaScript
Subject:   Detecting Acrobat Reader & others
Date:   2002-09-21 00:53:14
From:   anonymous2
Response to: Detecting Acrobat Reader

Try this
/This script detects the following:
//Flash
//Windows Media Player
//Java
//Shockwave
//RealPlayer
//QuickTime
//Acrobat Reader
//SVG Viewer



var agt=navigator.userAgent.toLowerCase();
var ie = (agt.indexOf("msie") != -1);
var ns = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);


if (ie && win) { pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes.type.toLowerCase();
pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}


function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }


pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);


//SAMPLE USAGE- detect "Flash"
//if (pluginlist.indexOf("Flash")!=-1)
//document.write("You have flash installed")

Full Threads Oldest First

Showing messages 1 through 11 of 11.

  • Detecting Acrobat Reader & others
    2003-11-19 02:33:19  anonymous2 [View]

    This file doesn´t work.
    what can i do
    • Detecting Acrobat Reader & others
      2005-02-23 08:22:37  Hulkman [View]

      Here's the full javascript code to detect any version of Acrobat:

      This works both for IE and NS and any version of Acrobat :)
      Hope it helps someone!

      the problem with the other scripts is that it doesn't work for Acrobat 7.0 as the type changed from PDF.PdfCtrl.version to AcroPDF.PDF.1

      this code corrects that problem!

      feedback appreciated!




      var acrobat=new Object();

      acrobat.installed=false;
      acrobat.version='0.0';

      if (navigator.plugins && navigator.plugins.length)
      {
      for (x=0; x {
      if (navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1)
      {
      acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]);

      if (acrobat.version.toString().length == 1) acrobat.version+='.0';

      acrobat.installed=true;
      break;
      }
      }
      }
      else if (window.ActiveXObject)
      {
      for (x=2; x<10; x++)
      {
      try
      {
      oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
      if (oAcro)
      {
      acrobat.installed=true;
      acrobat.version=x+'.0';
      }
      }
      catch(e) {}
      }

      try
      {
      oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
      if (oAcro4)
      {
      acrobat.installed=true;
      acrobat.version='4.0';
      }
      }
      catch(e) {}

      try
      {
      oAcro7=new ActiveXObject('AcroPDF.PDF.1');
      if (oAcro7)
      {
      acrobat.installed=true;
      acrobat.version='7.0';
      }
      }
      catch(e) {}

      }
      • Detecting Acrobat Reader & others
        2007-06-30 10:53:39  WebMaMa [View]

        Thanks for that code. However, I am getting an error in IE7 before the page loads.

        Line: 22
        Char: 13
        Error: Expected';'
        Code: 0
        URL: http://www.shirleywilliamsart.com/index2.html

        Can anyone please tell me what he the problem is???
      • Detecting Acrobat Reader & others
        2005-04-15 15:01:58  jas1114 [View]

        What is the rest of this for loop:

        if (navigator.plugins && navigator.plugins.length)
        {
        for (x=0; x ????????????
        {
        • Detecting Acrobat Reader & others
          2005-04-18 06:21:43  ales78 [View]

          It iterates through an array of plugins. Missing piece of code can looks like:

          for ( var x = 0, l = navigator.plugins.length; x < l; ++x )
          {
          ...
          }
          • Detecting Acrobat Reader & others
            2005-05-03 13:53:29  attheshow [View]

            Is there any way to get this to work in Firefox? Thanks.
            • Detecting Acrobat Reader & others
              2006-11-24 05:58:39  ramprakash [View]

              hi can any body tell me how can i detect acrobat
              reader in any machine in java script
            • Detecting Acrobat Reader & others
              2006-11-24 05:58:09  ramprakash [View]

              hi can any body tell me how can i detect acrobat
              reader in any machine in java script
  • what about other plug-ins ? msWord etc?
    2003-02-05 17:23:28  bnreyal [View]

    does anybody know where can i find the names of other plugins or viewers like msWord etc.
    • what about other plug-ins ? msWord etc?
      2003-02-13 07:08:04  anonymous2 [View]

      I've used the following objects:

      Scripting.FileSystemObject
      Outlook.Application
      Word.Application
      Excel.Application

      Remember that Javascript now has try...catch() syntax which I've successfully used to degrade gracefully if creating one of these objects fails (because it isn't installed/isn't working properly etc).

      Also remember to quit word [objWord.Quit()] on the onUnload event of the page, otherwise you'll build up quite a little collection of WINWOD.EXE processes... these WILL eventually crash your computer ;-)

      Good luck.
      • what about other plug-ins ? msWord etc?
        2003-05-29 21:46:33  anonymous2 [View]

        Why is navigator.plugins still empty in IE 6.0?
        var objWord = new ActiveXObject("Word.Application"); always give the message
        "An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?"

        which is really a irritating to a user...it would be nice to have some other workaround...