↑
Main Page
MIME Types Example
document.writeln(“<li>Filename: “ + oPlugin.filename
+ “</li>”);
document.writeln(“</ul>”);
}
}
document.writeln(“</ul>”);
}
</script>
</body>
</html>
This example outputs each MIME type complete with its plugin information (if one is available).
Just like the previous example, this page prints out the MIME types that are numerically indexed. Some
MIME types are indexed only by the MIME type string, and these are not accessible using this approach.
For instance,
text/html
is a registered MIME type with the browser, but it does not appear in the list
generated from the previous code. However, you can explicitly test for it:
alert( navigator.mimeTypes[“text/html”] != null);
These
invisible
MIME types are typically those handled by the browser itself and usually don’t have a
plugin registered to them. A simple page can be used to test any MIME type you can dream up:
<html>
<head>
<title>MIME Types Example</title>
<script type=”text/javascript”>
function findPlugin() {
var sType = document.getElementById(“txtMimeType”).value;
if (navigator.mimeTypes) {
if (navigator.mimeTypes[sType]) {
if (navigator.mimeTypes[sType].enabledPlugin) {
alert(“The MIME type \”” + sType
+ “\” uses the plugin \””
+ navigator.mimeTypes[sType].enabledPlugin.name
+ “\”.”);
} else {
alert(“The MIME type \”” + sType
+ “\” has no registered plugin.”);
}
} else {
alert(“The MIME type \”” + sType
+ “\” is not registered.”);
}
} else {
alert(“Browser doesn’t support navigator.mimeTypes.”);
}
}
</script>
537
Interacting with Plugins
21_579088 ch18.qxd 3/28/05 11:43 AM Page 537
Free JavaScript Editor
Ajax Editor
©
→