Determining installed plug-ins with JavaScript
This information will be added to the JavaScript Developer's Guide.
You can use JavaScript to determine whether a user has installed a particular plug-in; you can then display embedded plug-in data if the plug-in is installed, or display some alternative information (for example, an image or text) if it is not. You can also determine whether a client is capable of handling a particular MIME (Multipart Internet Mail Extension) type.
The navigator object has two properties for checking installed plug-ins:
- The mimeTypes object is an array of all MIME types supported by the client (either internally, via helper apps, or by plug-ins). Each element of the array is a mimeTypes object, which has properties for its type, description, file extensions, and enabled plug-ins.
- The plugins object is an array of all plug-ins currently installed on the client. Each element of the array is a plugins object, which has properties for its name and description as well as an array of mimeTypes objects for the MIME types supported by that plug-in.
Examples
The following script checks to see whether the Shockwave plug-in is installed and displays an embedded Shockwave movie if it is:
var myPlugin = navigator.plugins["Shockwave"];
if (myPlugin)
document.writeln("
The following script checks to see whether the client is capable of displaying QuickTime movies.
var myMimetype = navigator.mimeTypes["video/quicktime"]
if (myMimetype)
document.writeln("Click here to see a " + myMimetype.description)
else
document.writeln("Too bad, can't show you any movies.")
Properties of the mimeTypes object
The mimeTypes object has the following properties:
- type: the name of the MIME type, for example video/mpeg or audio/x-wav
- description: a description of the type
- enabledPlugin: a reference to the plugins object that handles the MIME type
- suffixes: a string listing possible file suffixes (also known as file name extensions) for the MIME type. This property is a string consisting of each valid suffix, typically three letters long, separated by commas.
For example, the following table summarizes the values for displaying JPEG images:
Expression
| Value
|
navigator.mimeTypes["image/jpeg"].type
| image/jpeg
|
navigator.mimeTypes["image/jpeg"].description
| JPEG Image
|
navigator.mimeTypes["image/jpeg"].suffixes
| jpeg, jpg, jpe, jfif, pjpeg, pjp
|
The following code displays the type, description, and suffixes properties for each mimeType object on a client:
document.writeln("",
"i",
" | type",
" | description",
" | suffixes |
")
for (i=0; i < navigator.mimeTypes.length; i++) {
document.writeln("",i,
" | ",navigator.mimeTypes[i].type,
" | ",navigator.mimeTypes[i].description,
" | ",navigator.mimeTypes[i].suffixes,
" |
")
}
document.writeln("
")
Properties of the plugins object
The plugins object has three basic properties and one array property.
- name: the name of the plug-in
- filename: the name of the plug-in file on disk
- description: a description supplied by the plug-in itself
- length: the number of elements in the array
- [...]: array of mimeTypes objects, indexed by number or type, that plug-in can handle
For example, the following assigns shorthand variables for the predefined Shockwave properties:
var myPlugin = navigator.plugins["Shockwave"].name
var myPluginFile = navigator.plugins["Shockwave"].filename
var myPluginDesc = navigator.plugins["Shockwave"].description