↑
Main Page
meaning that MIME types
if (navigator.mimeTypes) {
document.writeln(“<h3>Loaded Plugins:</h3>”);
document.writeln(“<ul>”);
for (var i=0; i < navigator.plugins.length; i++) {
document.writeln(“<li>” + navigator.plugins[i].name + “ (“
+ navigator.plugins[i].description + “)</li>”);
}
document.writeln(“</ul>”);
}
</script>
</body>
</html>
This page prints out a list of all registered plugins and their descriptions. But the plugin object holds a
secret; it is actually a collection of MIME types, meaning that MIME types for the plugin can be accessed
like this:
var oMimeType = navigator.plugins[0][0];
This line of code accesses the first MIME type supported by the first plugin. So now, you can update the
previous example to include the registered MIME types for each plugin:
<html>
<head>
<title>Plugins Example</title>
</head>
<body>
<script type=”text/javascript”>
if (navigator.mimeTypes) {
document.writeln(“<h3>Loaded Plugins:</h3>”);
document.writeln(“<ul>”);
for (var i=0; i < navigator.plugins.length; i++) {
document.writeln(“<li>” + navigator.plugins[i].name + “ (“
+ navigator.plugins[i].description + “)</li>”);
document.writeln(“<ul>”);
for (var j=0; j < navigator.plugins[i].length; j++) {
document.writeln(“<li>” + navigator.plugins[i][j].type +
“</li>”);
}
document.writeln(“</ul>”);
}
document.writeln(“</ul>”);
}
</script>
</body>
</html>
Now this example displays each plugin’s name and description, followed by a list of supported MIME
types.
539
Interacting with Plugins
21_579088 ch18.qxd 3/28/05 11:43 AM Page 539
Free JavaScript Editor
Ajax Editor
©
→