Selby Abbey

pluginDetect v0.2

Javascript library for detecting browser plugins

What is PluginDetect?

PluginDetect is a simple, flexible, object-oriented, unobstrusive Javascript library for detecting installed browser plugins, which are required to view VR panoramas. It is aimed at panorama producers and publishers. It is free to download and use - if you make any changes or improvements you are encouraged to submit them back to us so we may incorporate them in the script.

What are the requirements?

It has been tested and works correctly in the following browsers:

  • Firefox 1.5 (Win)
  • Internet Explorer 7 (Beta 3) (Win)
  • Internet Explorer 5.0 / 5.5 / 6 (Win)
  • Safari 2.0.4 (Mac)
  • Opera 8.5 / 9.01 (Win)
  • Netscape 7.1 (Win)
  • iCab 3.0.2 (Mac)

It does not work in:

  • Internet Explorer < 4.0 (Win)
  • Internet Explorer 5.2.3 (Mac)

It uses and requires the Prototype javascript framework, which greatly simplifies the scripting and reduces the size of the script. Prototype should be included in your HTML page before including the PluginDetect script.

Changelog

v0.2

  • Add more plugin types
  • Update detection code so a plugin may have more than one activeX name
  • Change the way Java is detected

v0.1

First release

How do I use it?

You must include the Prototype library, and the PluginDetect script in the head of your HTML document:

<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="plugindetect.js"></script>

All the configuration of PluginDetect can be done in a script in the head of your document. There are 3 steps:

  1. Create the PluginDetect object by telling it the plugins you want to detect
  2. Tell the object what actions you want to take for each plugin
  3. Do the detection

Here are some examples of its use for each of these stages.

Step 1

Creating an object to do the detection. If no specific plugins are listed, all plugins* are detected. It is also possible to specify which plugins to detect, and the order to do them in. This is useful if you, for example wanted to redirect to another page as soon as an installed plugin is found, giving you control over which is detected first.

Example 1

// Most basic setup - create a new PluginDetect object,
// detecting all plugins
pd = new PluginDetect();

Example 2

// Create a new PluginDetect object, detecting plugins
//in the order given
pd = new PluginDetect(
 { plugintypes: ['flash','quicktime','deval'] }
);

*Note the plugin types available to detect are defined in an array at the top of the PluginDetect script.

Step 2

Tell PluginDetect what to do when each plugin is found (or not). Use the addAction method to the PluginDetect object that has been created:

pd.addAction(plugin, status, action, actionType);

plugin = string, the name of the plugin to affect, e.g. flash, director, java, quicktime, etc
status = string, either 'installed' or 'notInstalled'
action = string, either a URL or a piece of javascript, or null if nothing should happen
actionType = string (optional) either 'url', 'redirect' 'js', or 'auto'

If omitted, the default is 'auto' - the script will determine if the action looks like a URL or not, and if it does, it will redirect to that address.
url
- the script will redirect and preserve the back button facility of the page
redirect - the script will redirect and not store the page with the script in the browser history
js - the script will treat the action as Javascript, even if it looks like a URL
stop - no more detections will take place, and the action string will be ignored

If no action is added to a particular status of a particular plugin, then nothing will happens, although the plugin will still be detected, and its status available through Javascript.

As many actions as required can be added to each plugin / status.

Example 3

// e.g. if Flash is installed, go to this URL -
// pressing the back button will not return to the
// page containing the script, but the one before
// it in the browser history
pd.addAction ('flash', 'installed', 'http://www.google.com');

Example 4

// e.g. if Flash is not installed, go to this URL -
// pressing the back button will return to this page and redetect
pd.addAction ('flash', 'notInstalled', 'http://www.macromedia.com/', 'url');

Example 5

// e.g. if Quicktime is installed, run this
// Javascript (quicktimeFound function) and then redirect
pd.addAction ('quicktime', 'installed', 'quicktimeFound();');
pd.addAction ('quicktime', 'installed', 'http://www.apple.com/');

Example 6

// e.g. if Director is not installed, don't do anything
// but continue with further plugin detections
pd.addAction ('director', 'notInstalled', null);

Example 7

// e.g. if Flash is not installed, don't do anything further
pd.addAction ('flash', 'notInstalled', null, 'stop');

Step 3

Once we have done all the setting up, we can actually do the detection.

// Do the detection
pd.detect();

If any of the actions include functions which are going to affect any item on the page, since at this point the DOM has not been created, it may be necessary to add the detection to the page onload event. Prototype provides an easy way of doing this:

// Do the detection on page load
Event.observe(window, 'load', pd.detect);

After detection

The following methods are available via Javascript after detection has been carried out:

allInstalledPlugins() - Returns an array of the names of all installed plugins

Example 8

var arrayOfPlugins = pd.allInstalledPlugins();

 

detectionComplete() - Checks if the detection has been done yet or not, returns true or false.

Example 9

if (!pd.detectionComplete() ) {
// Do this if the detection has not been done already
}