How to use the PluginDetect Javascript Library

We assume here that you have a copy of PluginDetect, and that in the <head> of your webpage you have included this HTML:
       <script type="text/javascript" src="PluginDetect.js"></script>

You only need to add some javascript code to your web page to detect the plugins you are interested in.

The javascript methods available in PluginDetect are as follows:

PluginDetect.getVersion(pluginName):  [Returns string or null]
   Returns the version (as a string) of the installed plugin. If multiple versions are detected, then the highest installed version is returned.
   Returns null when the version could not be determined (when plugin is not installed/not enabled, or plugin is installed but the version information is unavailable).

By default, the returned version string is comma delimited and has the format of "A,B,C,D". If you wish to change the getVersion( ) delimiter, then use:
   PluginDetect.getVersion(delimiter) where delimiter is a string with exactly 1 character.

For example,
   PluginDetect.getVersion(".");   // set delimiter
   var version = PluginDetect.getVersion("QuickTime");    // version has format of "A.B.C.D"

PluginDetect.isMinVersion(pluginName, minVersion):  [Returns number]
   Returns 1 if plugin is installed & enabled and plugin version is >= minVersion.

   Returns 0.5 if plugin detection has been initiated but is not yet completed. At this point in time, the plugin appears to be installed & enabled (but this is not a certainty). Detection is occurring NOTF (Not On The Fly), so you will have to wait until the detection has completed. Only certain plugins (on certain browsers and platforms) require NOTF.
   In order to handle NOTF detection, it is recommended that you use the onDetectionDone( ) method. This method will call an event handler after plugin detection has fully completed. The handler can call the isMinVersion( ) and getVersion( ) methods to obtain the final plugin detection results.

   Returns 0 if plugin installed & enabled but version is unknown (unable to determine if version >= minVersion).

   Returns -0.1 if plugin is installed & enabled, but plugin version is < minVersion.

   Returns -0.2 if plugin installed but not enabled. Some browsers occasionally reveal enough info to make this determination.

   Returns -0.5 if plugin detection has been initiated but is not yet completed. At this point in time, it is unknown whether the plugin is installed or not. Detection is occurring NOTF (Not On The Fly), so you will have to wait until the detection has completed. Only certain plugins (on certain browsers and platforms) require NOTF.
   In order to handle NOTF detection, it is recommended that you use the onDetectionDone( ) method. This method will call an event handler after plugin detection has fully completed. The handler can call the isMinVersion( ) and getVersion( ) methods to obtain the final plugin detection results.

   Returns -1 if plugin is not installed or not enabled.

   Returns -1.5 if plugin status is unknown. This only occurs for certain plugins or certain browsers.

   Returns -3 if you supplied a bad input argument to the isMinVersion( ) method.

NOTE: Some of these return values are only possible for certain plugins or certain browsers.

PluginDetect.hasMimeType(mt): [returns mimetype object given by navigator.mimeTypes[mt] or returns null]
   The input mt is a string (or an array of strings) that specifies a mimetype (or an array of mimetypes).
   For example, let us say that mt = "video/quicktime". If the mimetype mt is present and enabled in the browser, and the corresponding plugin is present and enabled, then PluginDetect.hasMimeType("video/quicktime") will return the mimetype object given by navigator.mimeTypes["video/quicktime"]. If the mimetype mt is not present or not enabled in the browser, then PluginDetect.hasMimeType("video/quicktime") will return null.
   On the other hand, let us say that mt specifies multiple mimetypes such that mt = ["video/quicktime", "image/x-quicktime"]. Then PluginDetect.hasMimeType(mt) will return the mimetype object for either of these 2 mimetypes if either one is present and enabled. If neither mimetype is present and enabled, then PluginDetect.hasMimeType(mt) will return null.
   Note: with the introduction of Internet Explorer 11+/Windows 8+, it is now possible for Internet Explorer to have values in the navigator.mimeTypes[ ] and navigator.plugins[ ] arrays. Therefore the hasMimeType( ) method is capable of returning a value for IE and non-IE browsers. This assumes that the plugin installers take advantage of Internet Explorer 11+ ability to have mimeTypes[ ] and plugins[ ] arrays.

PluginDetect.onDetectionDone(pluginName, f, ...): [Returns number]
   This method will initiate plugin detection when needed, and will execute the event handler f after the plugin detection results become available. onDetectionDone( ) can handle both OTF (on the fly) and NOTF (not on the fly) plugin detection. The event handler f automatically receives the PluginDetect object as an input argument such that we have f(PluginDetect){ ... }. You are free to use getVersion( ), isMinVersion( ), and getInfo( ) inside event handler f.
   Returns 1 if plugin detection is done (OTF) and handler f has been called.
   Returns 0 if plugin detection is not done yet (NOTF) and handler f has not been called yet. Handler f will be called after detection has been completed.
   Returns -1 if error (plugin name input argument not specified correctly).

PluginDetect.onBeforeInstantiate(pluginName, f):
   
Executes the event handler f immediately before PluginDetect attempts to instantiate the plugin. [By instantiate, we mean that an instance of the plugin is inserted into your web page. This will cause the plugin to start up and run, assuming it is installed.] The event handler automatically receives the PluginDetect object as an input argument such that we have f(PluginDetect){ ... }.
  Sometimes during detection, it may be necessary for PluginDetect to instantiate (or attempt to instantiate) the plugin. Should this attempt be neccessary, the event handler f will run first, and then the plugin will attempt to instantiate. [Note: If the plugin is installed and enabled, then it instantiates. If it is not installed or not enabled, then it will not instantiate. Either way, the handler f will run before the attempt is made.]
  In order for the onBeforeInstantiate( ) method to work correctly, you must place it BEFORE detection is started for the plugin. In other words, use it before getVersion(pluginName), isMinVersion(pluginName), and onDetectionDone(pluginName). As an example:
       var PD = PluginDetect;
       var F1 = function($){ ... };        // $ input arg is the PluginDetect object
       PD.onBeforeInstantiate("Java", F1);
       var F2 = function($){ var version = $.getVersion("Java"); alert(version); };
       PD.onDetectionDone("Java", F2, "getJavaInfo.jar");

PluginDetect.getInfo(pluginName, ...): [object or null]
   Returns null if no information is available for this plugin.
   Returns an object with several useful properties. For details on how to use this method with a specific plugin, see the specific plugin pages (such as for ).

PluginDetect.onWindowLoaded( f ):
   Executes the event handler f after the browser window has fully loaded. The event handler f automatically receives the PluginDetect object as an input argument such that we have f(PluginDetect){ ... }. You are free to use getVersion( ), isMinVersion( ), getInfo( ), onDetectionDone( ), and onBeforeInstantiate( ) inside event handler f.

Event handler f without user input arguments:
   If the user does not specify any input arguments for event handler f, then the relevant PluginDetect methods are in the format of
       PluginDetect.onDetectionDone(pluginName, f, ...)
       PluginDetect.onWindowLoaded(f)
       PluginDetect.onBeforeInstantiate(pluginName, f)

When the handler f is executed it automatically receives the PluginDetect object as input such that we have f(PluginDetect){ ... }.

Event handler f with user input arguments:
   You may specify up to 3 inputs (ie. arg1, arg2, and arg3) for the event handler. The trick is to use an array such as [f, arg1, arg2, arg3]. The relevant PluginDetect methods are in the format of
       PluginDetect.onDetectionDone(pluginName, [f, arg1, arg2, arg3], ...)
       PluginDetect.onWindowLoaded( [f, arg1, arg2, arg3] )
       PluginDetect.onBeforeInstantiate(pluginName, [f, arg1, arg2, arg3])

When the handler f is executed it automatically receives the PluginDetect object as input such that we have f(PluginDetect, arg1, arg2, arg3){ ... }.


pluginName: [string input argument]
   The name of the plugin being detected.
   pluginName may have one of the following values: .
   pluginName is case insensitive.

minVersion: [string or number input argument]
   This is the minimum plugin version.
   Can be a string such as  "1,5,0,0" or "1.5" or "1,5,0,1" or "1.5.0.1" etc...
   Can be a number such as 0 or 1.5 or 1.50 etc...
   If minVersion is not specified, then PluginDetect will assume minVersion is "0".
   Strings are more versatile than numbers since "1,5,0,1" cannot be expressed as a number.


<div id="plugindetect"></div> container:  [optional HTML element in your web page to assist in plugin detection]
   PluginDetect sometimes needs to add <object> and/or <applet> tags to your web page to accomplish plugin detection (for Java, DevalVR, WindowsMediaPlayer, Silverlight, RealPlayer, Flash, Adobe Reader, PDFReader). These <object>/<applet> tags are all placed into the same <div id="plugindetect" ></div> container.
   The user is free to place their own <div> into the web page if they wish. However, this should normally not be necessary since the PluginDetect script will automatically add the <div> container to the DOM when needed. But if you do wish to specify your own <div>, then you should obey the following rules:

1) The <div> container must be placed inside the <body></body>. You are allowed to nest the <div> inside another <div> if you wish.

2) The <div> must have an id of "plugindetect" such that we have:
          <div id="plugindetect"></div>

3) The PluginDetect script must be able to find the <div> when it is doing detection. It finds the <div> using document.getElementById("plugindetect"). All this means is that the <div> must be rendered by the browser by the time that the plugin detection is occurring. For example, you are allowed to do this:
          <div id="plugindetect"></div>
          <script type="text/javascript">
              var version = PluginDetect.getVersion("Flash");
          </script>

You are also allowed to do this:
          <script type="text/javascript">
              var T = function( ){var version = PluginDetect.getVersion("Flash");};
              PluginDetect.onWindowLoaded(T);
          </script>
         <div id="plugindetect"></div>

But you should NOT do this (because detection occurs before the div is rendered):
          <script type="text/javascript">
              var version = PluginDetect.getVersion("Flash");
          </script>
          <div id="plugindetect"></div>

4) At some point, you may decide that you want to hide the <div> in some way, so the user cannot see it anywhere in the web page. That should be ok. However, you should NOT set ccs "visibility:hidden" or "display:none" for the <div>, because this could prevent the instantiated plugins from running properly. Instead, you could position it off screen by using style="position:absolute; left:-500px; top:-500px;", or something along those lines. (This is what PluginDetect does when it automatically generates the <div>).

5) You are generally free to set any other css properties you wish. Just make sure that the <div> has a height of at least 4 pixels, and a width of at least 50 pixels.

6) Here are a few examples of the <div> (we leave out the plugin detection code here for simplicity)...

  i) No css settings at all
       <body>
       <div id="plugindetect"></div>
       </body>

  ii) Here the <div> is positioned in the top left corner of the <body>
       <body>
       <div id="plugindetect" style="position:absolute; left:0px; top:0px;"></div>
       </body>

  iii) Here the <div> is positioned in the top right corner of the <body>
       <body>
       <div id="plugindetect" style="position:absolute; right:0px; top:0px;"></div>
       </body>

  iv) Here the <div> is positioned in the top left corner of its parent <div>
       <body>
       <div style="position:relative;">
           <div id="plugindetect" style="position:absolute; left:0px; top:0px;"></div>
       <div>
       </body>


NOTE: For some plugins, there is a more complete set of instructions available on the individual plugin pages. The plugins are listed in the menu in the left-hand column of this page.

There are also a few other methods/properties of PluginDetect that you may find useful:

PluginDetect.browser.isIE:  [Boolean]
  [This property is independent from the navigator.userAgent]
   Returns true if the browser is Internet Explorer.
   Returns false if the browser is not Internet Explorer.

PluginDetect.browser.verIE:  [null or number]
   [If you select the option "Use better Internet Explorer version detection" on the PluginDetect download page, then PluginDetect.browser.verIE will equal (PluginDetect.browser.verIEtrue || PluginDetect.browser.docModeIE). This means that PluginDetect.browser.verIE will usually get its value from PluginDetect.browser.verIEtrue, and if that fails then it gets its value from PluginDetect.browser.docModeIE. Either way, PluginDetect.browser.verIE will virtually always be independent from the navigator.userAgent.]
   [If you do NOT select the option "Use better Internet Explorer version detection" on the download page, then PluginDetect.browser.verIE will get its value from the navigator.userAgent.]
   Returns the version of Internet Explorer.
   Returns null if the browser is not Internet Explorer.

PluginDetect.browser.verIEtrue: [null or string]
   [This property is only available if you select the option "Use better Internet Explorer version detection" on the PluginDetect download page.]
   Returns the TRUE version (as a string) for Internet Explorer. The string format will be "AA.BB.CCCC.DDDD". This version string is independent of the browser’s navigator.userAgent/document mode/browser mode. This string value is only available for Internet Explorer version < 11.
   Returns null otherwise.

PluginDetect.browser.docModeIE: [null or number]
   [This property is only available if you select the option "Use better Internet Explorer version detection" on the PluginDetect download page]
   Returns the document mode of Internet Explorer. This is basically the version of Internet Explorer that renders your web document. It tells you the level of HTML/CSS/Image support the browser has when displaying your web page. If the number is 6 or higher, then the browser is in Standards Mode. If the number is 5, then the browser is in Quirks mode.
   You can use PluginDetect.browser.docModeIE to help dynamically select the proper CSS rules for each version of Internet Explorer. Traditionally, conditional comments have been used for this purpose, but conditional comments are no longer supported in IE 10+.
   Returns null otherwise.

PluginDetect.browser.ActiveXEnabled:  [Boolean]
   Returns true if browser is Internet Explorer and ActiveX is enabled in the browser settings (ActiveX should be enabled in IE for PluginDetect to work).
   Returns false otherwise.

PluginDetect.browser.ActiveXFilteringEnabled: [Boolean]
   Returns true if browser is Internet Explorer 9+ and ActiveX filtering is enabled in the browser settings. When filtering is enabled then most (but not necessarily all) plugins/addons will be disabled.
   Returns false otherwise.

PluginDetect.browser.isGecko: [Boolean]
   Returns true if the browser is Gecko based (ie. Firefox, Mozilla, Netscape, Flock, SeaMonkey, K-Meleon, etc...).
   Returns false if the browser is not Gecko based.

PluginDetect.browser.verGecko: [null or string]
   Returns a version number (as a string) of the Gecko version if the browser is Gecko based. The string contains the CVS branch tag of the source code used to create the version of Gecko in your browser. The branch tag is contained in navigator.userAgent and follows the string 'rv:'.
   Returns null if the browser is not Gecko based.

PluginDetect.browser.isSafari: [Boolean]
   Returns true if browser is Safari, false otherwise.

PluginDetect.browser.verSafari: [null or string]
   Returns a version number for Safari 3+.

PluginDetect.browser.isChrome: [Boolean]
   Returns true if browser is Chrome, false otherwise.

PluginDetect.browser.verChrome: [null or string]
   Returns a version number (as a string) of the Chrome browser.
   Returns null if the browser is not Chrome.

PluginDetect.browser.isOpera: [Boolean]
   Returns true if browser is Opera, false otherwise.

PluginDetect.browser.verOpera: [null or string]
   Returns a version number (as a string) of the Opera browser.
   Returns null if the browser is not Opera.
[  Please note that the version numbers for older Opera browsers only had one decimal point. For example, Opera 9.00, 10.01, 10.10, 12.15, etc... The corresponding string values for PluginDetect.browser.verOpera would be "9,0,0,0", "10,1,0,0", "10,10,0,0", "12,15,0,0".
   The version numbers for newer Opera browsers have 3 decimal points, such as 22.0.1471.70. The corresponding string value for PluginDetect.browser.verOpera in this case would be "22,0,1471,70". ]

PluginDetect.browser.isEdge: [Boolean]
   Returns true if browser is Microsoft Edge, false otherwise.

PluginDetect.browser.verEdgeHTML: [null or string]
   Returns a version number (as a string) of the Edge HTML layout engine for the Microsoft Edge browser.
   Returns null if the browser is not Edge.


Note: it is normally frowned upon to use browser detection in one’s Javascript. However, some browsers may have certain quirks/bugs, and so PluginDetect needs to know which browser it is running on in order to make plugin detection work a little more smoothly.


Loading the PluginDetect Library

There are 2 different ways that you may load the PluginDetect library:

A) statically load the library.

For example...

<head>    
  <script type="text/javascript" src="PluginDetect.js"></script>
</head>


or...

<body>
  <script type="text/javascript" src="PluginDetect.js"></script>
</body>



B) dynamically load the library.

Using Javascript, you can create a <script> element, let the src property point to the library, and then insert the <script> element into the DOM. Once the PluginDetect library has loaded, you are free to perform your plugin detection.



Definition of OTF & NOTF detection

Plugin detection is performed either "on the fly" (OTF) or "not on the fly" (NOTF) in your script.

If a single PluginDetect command (like PluginDetect.isMinVersion( ) or PluginDetect.getVersion( ) ) is able to initiate detection, complete that detection, and return a final detection result, then the detection is OTF. For example, the VLC Player plugin always uses OTF:

// Example # 1
//
// Plugin detection is initiated in the next line of code.

var status = PluginDetect.isMinVersion("VLC", "2");

// By the time the Javascript interpreter reaches this point, plugin detection
// for VLC Player will be complete.


The status variable in Example 1 will contain the final detection result for VLC Player. The status variable will have a value of 1, 0, -0.1, -0.2, or -1. Thus the detection was performed OTF (on the fly).

On the other hand, suppose we wanted to detect the Java plugin:

// Example # 2
//
// Plugin detection is initiated in the next line of code.

var status = PluginDetect.isMinVersion("Java", "1.6", "getJavaInfo.jar" );

// By the time the Javascript interpreter reaches this point, plugin detection
// for Java may or may not be complete. It depends on the value of the 'status' variable.


Depending on the browser/platform/Java version, the status variable in Example 2 could receive a value of -0.5 or +0.5. This means that plugin detection has not been completed yet. The status variable does not contain the final detection result for Java. Because the isMinVersion( ) method initiated detection but was unable to return the final detection result, we say that NOTF (not on the fly) detection is occurring.

[Note: It is also possible for the Java status variable to receive a value of 1, 0, -0.1, -0.2, or -1. That would be OTF.]

So, how do we handle NOTF to get the final detection result for Java? It’s actually quite simple. We wait long enough until the detection has completed, and then query PluginDetect for the result. We do this with the onDetectionDone( ) method, which can handle both OTF and NOTF detection:

// Example # 3

var displayResults = function($$){

   var status = $$.isMinVersion("Java", "1.6");
   var version = $$.getVersion("Java");
   alert(status);

};

// Plugin detection is initiated by onDetectionDone( ).
// When detection is completed, the event handler runs.

// onDetectionDone( ) will work for both OTF and NOTF.
PluginDetect.onDetectionDone("Java", displayResults, "getJavaInfo.jar");


The PluginDetect.onDetectionDone( ) method initiates the plugin detection, waits until the detection is done, and then runs the event handler.



PluginDetect is Unobtrusive

The PluginDetect script has been made as unobtrusive as possible so as to not interfere with any other scripts you are using. It uses only 1 name in the global namespace: PluginDetect (an object). Any other variable names that you see in the PluginDetect script are local variables only, and will not affect the global namespace or any other scripts.

Some people have noticed that I use the '$' variable name in PluginDetect, and have wrongly assumed that this means that PluginDetect will interfere with the Prototype script (which defines a $( ) method). Again, the '$' variable in PluginDetect is a local variable only, and will not interfere with the global $( ) method of Prototype.



A note about window.ActiveXObject

If you intend to run Javascript code that modifies or assigns a value to window.ActiveXObject, then you should do so only AFTER the <script> tag that loads the PluginDetect library. This way plugin detection for Internet Explorer will work as intended. If you modify the value of window.ActiveXObject BEFORE the library loads, then plugin detection for Internet Explorer will not work.

As a general rule, however, you should not modify the value of window.ActiveXObject at all.





Top of Page