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:


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("<EMBED SRC='Movie.dir' HEIGHT=100 WIDTH=100>") else document.writeln("You don't have Shockwave installed!")</SCRIPT>

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 <A HREF='movie.qt'>here</A> 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:

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("<TABLE BORDER=1><TR VALIGN=TOP>", "<TH ALIGN=left>i", "<TH ALIGN=left>type", "<TH ALIGN=left>description", "<TH ALIGN=left>suffixes</TR>") for (i=0; i < navigator.mimeTypes.length; i++) { document.writeln("<TR VALIGN=TOP><TD>",i, "<TD>",navigator.mimeTypes[i].type, "<TD>",navigator.mimeTypes[i].description, "<TD>",navigator.mimeTypes[i].suffixes, "</TR>") } document.writeln("</TABLE>")

Properties of the plugins object

The plugins object has three basic properties and one array property.

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