Main Page

HTML page

<p>Type the name of the <acronym title=”Multipurpose Internet Mail
you want to check and click the Find Plugin button.</p>
<p><input type=”text” id=”txtMimeType” />
<input type=”button” value=”Find Plugin” onclick=”findPlugin()” /></p>
The HTML page listed previously allows you to enter a MIME type into a text box and click a button
to determine if a MIME type is registered. If so, you can tell whether it has a browser plugin. The
function retrieves the value from the text box and first checks to see if the
collection exists. If it does, then the function continues on to see if the MIME type is
defined. If it is, you can tell whether it has a plugin installed.
You can extract the methodology to test for a plugin that handles a particular MIME type into a separate
function hasPluginForMimeType(sMimeType) {
if (navigator.mimeTypes) {
return navigator.mimeTypes[sMimeType].enabledPlugin != null;
} else {
return false;
Then, you can check for the existence of a given plugin like so:
if (hasPluginForMimeType(“application/x-shockwave-flash”)) {
alert(“The Flash plugin is installed.”);
} else {
alert(“The Flash plugin is not installed.”);
It’s also possible to retrieve a list of all registered plugins without using the MIME types. The
collection contains all plugins, indexed by name and by number, available for
the given browser. Each entry in the collection is a plugin object equivalent to the one referenced by
for each MIME type. So, if you know the name of a plugin (equivalent to its
property), you can access it directly:
var oFlashPlugin = navigator.plugins[“Shockwave Flash”];
Otherwise, you can iterate through the plugins to print out the information about each one. A simple
page can also be used to do this:
<title>Plugins Example</title>
<script type=”text/javascript”>
Chapter 18
21_579088 ch18.qxd 3/28/05 11:43 AM Page 538

JavaScript EditorFree JavaScript Editor     Ajax Editor