How to use the PluginDetect script

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. By default, the returned version string is comma delimited and has the format of "A,B,C,D".
   Returns null when the version could not be determined (when plugin is not installed/enabled, or plugin is installed but the version information is unavailable).

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("Java");    // version output now has the 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 (Java only) if plugin detection has been initiated but is not yet completed. The +0.5 number only occurs for NOTF detection of the Java plugin. This result means that the plugin is installed (& enabled), but the plugin version is unknown at this point in time. The version info may or may not be available at a later time. When the plugin detection has been completed, the isMinVersion() method will return 1, 0, or -1.
   Returns 0 if plugin installed (& enabled) but version is unknown (unable to determine if version >= minVersion).
   Returns -0.2 (Java/Silverlight) if plugin installed but not enabled. Some browsers occaisonally reveal enough info to make this determination.
   Returns -0.5 (Java only) if plugin detection has been initiated but is not yet completed. The -0.5 number only occurs for NOTF detection of the Java plugin. This result means that it is not known yet whether the plugin is installed or what the plugin version is. When the plugin detection has been completed, the isMinVersion() method will return 1, 0, or -1.
   Returns -1 if plugin version < minVersion, or if plugin is not installed / not enabled.
   Returns -2 if ActiveX is disabled (for Internet Explorer, this prevents plugin detection).
   Returns -3 if you supplied a bad input argument to the isMinVersion() method.

PluginDetect.onDetectionDone(pluginName, f, jarfile, verifyTagsArray): [Returns number]
   Even though you can use this method for any plugin, you only really need to use it for NOTF Java detection. The jarfile and verifyTagsArray input args are only used when pluginName is 'Java'.
   The method will initiate plugin detection if needed, and will execute the event handler f after the plugin detection results become available. The event handler f automatically receives the PluginDetect object as an input argument such that we have f(PluginDetect){ ... }.
   This method is useful as sometimes Java detection results are available at unpredictable times - meaning that Java detection is not always possible "on the fly". Hence, the onDetectionDone() method will wait as long as necessary until the Java detection has completed before executing handler f. You are free to use getVersion() and isMinVersion() inside handler f to see the detection results.
   Returns 1 if plugin detection is done (OTF) and handler f has been executed.
   Returns 0 if plugin detection is not done yet (NOTF) and so handler f has not been executed yet.
   Returns -1 if error (plugin name input argument not specified correctly).

PluginDetect.beforeInstantiate(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 beforeInstantiate() 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.beforeInstantiate('Java', F1);
       var F2 = function($){ var version = $.getVersion('Java'); alert(version); };
       PD.onDetectionDone('Java', F2, 'getJavaInfo.jar');

PluginDetect.onWindowLoaded( f ):
   Executes the event handler f after the browser window has fully loaded, and after the plugin detection results are available. 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(), onDetectionDone(), and beforeInstantiate() 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.beforeInstantiate(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.beforeInstantiate(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]
   This is the name of the plugin such as  'Java', 'QuickTime', 'DevalVR', 'Shockwave', 'Flash', 'WindowsMediaPlayer', 'Silverlight', or 'VLC'

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.

jarfile: [string input argument, optional but strongly recommended]
   This is the path/filename to the getJavaInfo.jar applet for Java detection. Even though it is an optional input, it is strongly recommended that you use the jarfile input argument when doing Java detection. Otherwise a number of Java cases will not be detectable. The jarfile path is relative to the web page itself, not relative to any external javascript file you may be using. For example,
           jarfile = 'getJavaInfo.jar' means the applet is in the same folder as your web page.
           jarfile = 'ABC/getJavaInfo.jar' means the applet is in a subfolder ABC.

   There are 2 versions of the jarfile available. Version 1 of the jarfile is named "getJavaInfo.jar" and is 359 bytes. Version 2 of the jarfile is named "getJavaInfo2.jar" and is 485 bytes. Both versions of the jarfile are compatible with PluginDetect, and you may use either version in your Java detection scripts. (Do NOT try to use both versions in the same web page.)
   The version 1 jarfile (getJavaInfo.jar) allows PluginDetect to query the JRE directly to determine the Java version and Java vendor. The version 2 jarfile (getJavaInfo2.jar) does everything that version 1 does, AND also the following:

        a) it allows PluginDetect to query the JRE for any additional Java properties that the JRE is willing to reveal. The query is in the format of System.getProperty(S) where S could be 'java.version', 'java.vendor', 'java.vm.name', 'java.vm.specification.name', etc... This feature is currently not being utilized by PluginDetect, but it will be in a future PluginDetect version.

        b) it allows PluginDetect to try to erase the "Applet A Started" message in the browser statusbar, which occurs in some browsers when the jarfile applet is running. The erase will only work if the browser allows this. The erase occurs from Java via the applet, not purely from Javascript. This is mostly intended for some older browsers, which tend to leave the "Applet A Started" message in the statusbar even after the page has fully loaded.   


<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). These <object>/<applet> tags are all placed into the same <div id="plugindetect" ></div> container. If the user does not specify the <div id="plugindetect" > container in the web page, then the PluginDetect script will automatically add the container to the page when needed. When detection has been completed, the contents of the div will be deleted.
   If you wish to place your own plugindetect <div> into your web page, 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('Java', 'getJavaInfo.jar');
          </script>

You are also allowed to do this:
          <script type="text/javascript">
              var T = function(){var version = PluginDetect.getVersion('Java', 'getJavaInfo.jar');};
              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('Java', 'getJavaInfo.jar');
          </script>
          <div id='plugindetect'></div>

4) Do not set the ccs visibility:hidden or display:none for the <div>. This could prevent the instantiated plugins from running properly.

5) PluginDetect automatically sets the <div> css properties for width, height, outline, border, padding, margin, display, and visibility. So you do not have to bother setting those yourself.

6) You are allowed to set the <div> css properties for position, left (or right), and top (or bottom). Note that position:absolute means that the <div> is positioned relative to its parent, and that it does not displace any other elements in your web page.
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>

7) I do not recommend that you specify an absolute position that is off the screen, because I cannot guarantee how an instantiated plugin will behave in that case. You are free to experiment if you like, however. Here is an example where the <div> is off screen and therefore completely hidden from view:
       <body>
       <div id='plugindetect' style='position:absolute; left:-9999px; top:0px;'></div>
       </body>


In addition to the methods discused above, there are a few that are available only for Java:

PluginDetect.getInfo('Java', jarfile): [object]
   Returns an object with several useful properties. The properties are listed below.

PluginDetect.getInfo('Java', jarfile).OTF: [number]
   Returns 0 if Java detection has been performed on the fly (OTF).
   Returns 1 if Java detection is being performed not on the fly (NOTF) but is not completed yet.
   Returns 2 if Java detection has been performed not on the fly (NOTF) and is complete.

PluginDetect.getInfo('Java', jarfile).DeploymentToolkitPlugin: [Boolean]
   Returns true if the Deployment Toolkit browser plugin is installed and enabled.
   Returns false if Deployment Toolkit browser plugin is not installed or not enabled.

PluginDetect.getInfo('Java', jarfile).DeployTK_versions: [Array of strings]
   If the Deployment Toolkit browser plugin is installed, then this array will contain a sorted list of all Java versions that that were detected by the Deployment Toolkit plugin. The purpose of this array is to detect multiple JREs. The version strings are in the exact same format used by the Deployment Toolkit plugin (ie. "1.5.0_04", "1.6.0._03", etc...).

PluginDetect.getInfo('Java', jarfile).MimeType_versions: [Array of strings]
   Suppose your browser has one or more mimetypes of the format "application/x-java-applet;jpi-version=A.B.C_DE". Then this array will contain a sorted list of installed Java versions based on these given mimetypes. The purpose of this array is to detect multiple JREs. The version strings are in the exact same format as those in the mimetypes array (ie. "1.5.0_04", "1.6.0._03", etc...).

PluginDetect.getInfo('Java', jarfile).All_versions: [Array of strings]
   This array contains a sorted list of all detected Java versions from all possible sources (including DeployTK_versions array, MimeType_versions array, and others).

PluginDetect.getInfo('Java', jarfile).vendor: [string]
   The Java vendor. Possible value are Sun Microsystems, Apple Inc, Microsoft Corp., etc...

PluginDetect.getInfo('Java', jarfile).AppletHTML: [string]
   If the jarfile is used to detect Java, then AppletHTML will show the HTML used to instaniate the applet. When AppletHTML is an "" empty string, then some other method was used to detect Java.

PluginDetect.getInfo('Java', jarfile).name: [string]
   The plugin name as given in the navigator.plugins array.

PluginDetect.getInfo('Java', jarfile).description: [string]
   The plugin description as given in the navigator.plugins array.



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

PluginDetect.hasMimeType( mt ): [returns mimetype object from navigator array or returns null]
   The input mt is a string or an array of strings that specifies a mimetype.
   For example, let us say that mt = 'video/quicktime'. If the mimetype mt is present and enabled in the browser, then PluginDetect.hasMimeType('video/quicktime') will return the mimetype object (from the navigator array) corresponding to that mimetype. 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's say that mt specifies multiple mimetypes such that mt = ['video/quicktime', 'image/x-quicktime']. Then PluginDetect.hasMimeType() 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() will return null.

PluginDetect.isIE:  
[boolean]
   Returns true if the browser is Internet Explorer.
   Returns false if the browser is not Internet Explorer.

PluginDetect.IEver:  [number]
   Returns version of Internet Explorer.

PluginDetect.ActiveXEnabled:  [boolean]
   Returns true if browser is Internet Explorer and ActiveX is enabled in the browser settings (ActiveX must be enabled for PluginDetect to work).

PluginDetect.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.GeckoRV: [null or string]
   Returns a string 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.isSafari: [Boolean]
   Returns true if browser is Safari, false otherwise.

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

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

Note above: it is normally frowned upon to use browser detection in one's Javascript, but in this case it appears to be necessary. Each browser has it's own particular quirks and bugs, and so PluginDetect needs to know which browser it is running on in order to make the plugin detection work a little more smoothly.



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.


Top of Page