The navigator object has a property called plugins which returns an array of all plug-ins installed in the browser. Each array element entry has following properties:

  • name - The name of the plugin.
  • filename - The executable file loaded to install plugin.
  • description - The description of the plugin supplied by developer.
  • length  -  The number of MIME types handled by this plugin.

Each plugin has an array of MimeType objects. They have 4 properties: description of MIME type, a pointer to plugin object called enabledPlugin, suffixes for the MIME types, which are basically file extensions and string which denotes the MIME type. They all can be individually accessed by a bracket notation.         

Syntax

var plugins = navigator.plugins;

The syntax returns the plugin array which can be used to access individual items through index, like plugins[0] or with methods like item(index) or namedItem(“name”).

The program below returns a list of plugins installed. The same can also be obtained using about:plugins in browsers location bar.

Example of a navigator.plugins property

The ‘Name’ label from the example's output contains information to identify a plug-in. JavaScript can be written to identify if a plug-in is installed or not. The hasPlugin() example shown below takes the name or partial name of the plugin and iterates through the plugin list. If the indexes of the passed name and the stored plugin name matches, it returns true indicating the plugin is installed.

Example with detection if a plugin exists or not by using hasPlugin property

The hasPlugin property is supported by most browsers, however IE10 and earlier versions were using ActiveXObject, the proprietary object type to detect plugins. Hence to write a cross-functional script we need to update the code as below:

Example of plugin detection with ActiveXObject property

var plugiName = navigator.plugins[“Contoso.Control”];
if(plugiName){
    //Check if the plugin is available
}
else{
    try{
        new ActiveXObject(“Contoso”);
        //Plugin available
    }
    catch(err){
        //plugin is not available
    }
}

 

›› go to examples ››