18.04.2016 Views

Professional JavaScript For Web Developers

javascript for learners.

javascript for learners.

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Interacting with Plugins<br />

if (navigator.mimeTypes) {<br />

document.writeln(“Loaded Plugins:”);<br />

document.writeln(“”);<br />

for (var i=0; i < navigator.plugins.length; i++) {<br />

document.writeln(“” + navigator.plugins[i].name + “ (“<br />

+ navigator.plugins[i].description + “)”);<br />

}<br />

document.writeln(“”);<br />

}<br />

<br />

<br />

<br />

This page prints out a list of all registered plugins and their descriptions. But the plugin object holds a<br />

secret; it is actually a collection of MIME types, meaning that MIME types for the plugin can be accessed<br />

like this:<br />

var oMimeType = navigator.plugins[0][0];<br />

This line of code accesses the first MIME type supported by the first plugin. So now, you can update the<br />

previous example to include the registered MIME types for each plugin:<br />

<br />

<br />

Plugins Example<br />

<br />

<br />

<br />

if (navigator.mimeTypes) {<br />

document.writeln(“Loaded Plugins:”);<br />

document.writeln(“”);<br />

for (var i=0; i < navigator.plugins.length; i++) {<br />

document.writeln(“” + navigator.plugins[i].name + “ (“<br />

+ navigator.plugins[i].description + “)”);<br />

document.writeln(“”);<br />

“”);<br />

for (var j=0; j < navigator.plugins[i].length; j++) {<br />

document.writeln(“” + navigator.plugins[i][j].type +<br />

}<br />

document.writeln(“”);<br />

}<br />

document.writeln(“”);<br />

}<br />

<br />

<br />

<br />

Now this example displays each plugin’s name and description, followed by a list of supported MIME<br />

types.<br />

539

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!