Accessibility
 
Home > Products > Dreamweaver > Support > Editing HTML in Dreamweaver
Dreamweaver Icon Macromedia Dreamweaver Support Center - Editing HTML in Dreamweaver
Checking for specific MIME types and plugins

Suppose you have a very small sound file that you'd like to use on your website. You consider that it's worthwhile to use it if the sound will play directly from the page, but not worth the trouble if the browser has to launch an external player. Netscape's Live Audio plugin makes it possible to play sounds from the page. So you can write a script like the following that checks for the plugin-in and writes the HTML to embed the sound only if the plugin is installed:

<SCRIPT LANGUAGE="JavaScript">
if (navigator.plugins['LiveAudio']){
document.write('<EMBED NAME="mySound" SRC="sound.wav" LOOP=false AUTOSTART=false MASTERSOUND HIDDEN=true VOLUME=100 WIDTH=0>');
}
</SCRIPT>
If you want to make sure that the browser supports WAV files with a plugin, you could check for the MIME type audio/wav and its enabledPlugin property with the following code:
<SCRIPT LANGUAGE="JavaScript">
if (navigator.mimeTypes['audio/wav'] && navigator.mimeTypes['audio/wav'].enabledPlugin){
document.write('<EMBED NAME="mySound" SRC="sound.wav" LOOP=false AUTOSTART=false MASTERSOUND HIDDEN=true VOLUME=100 WIDTH=0>');
}
</SCRIPT>
In the case of Shockwave, checking for a supported MIME type is virtually the same as checking for a plugin because Shockwave is handled only by a plugin or an ActiveX control and not by the browser or a helper application. It is not necessary to check the enabledPlugin property of the MIME type. For example, you could write the following code to check for Shockwave Flash support:
<SCRIPT LANGUAGE="JavaScript">
if (navigator.mimeTypes['application/x-shockwave-flash']){
document.write('This browser can read Shockwave files created with Flash 2.0');
}
else if (navigator.mimeTypes['application/futuresplash']){
document.write('This browser can only read Shockwave Flash files saved in .spl (Flash 1.0) format.');
}
else {
document.write('This browser cannot read Shockwave Flash files.');
}
</SCRIPT>
Note: By stating in plain English the expected outcome of each branch of your script (using document.write or alert), you can test the script in a browser immediately to see if the logic holds. If the logic is faulty, you can correct your if/else statements before lots of code obscures simple errors.

The preceding code looks first for the MIME type application/x-shockwave-flash , introduced with Flash 2.0. If the code can't find that, it looks for application/futuresplash . If the latter isn't installed either, the script reports that the browser cannot read Shockwave Flash files. The second check is performed only if the first one fails, and the final else is reached only if both checks fail. If the second check did not have an else in front of it, browsers with Shockwave Flash 2.0 installed would report "This browser can read Shockwave files created with Flash 2.0" and "This browser can only read Shockwave Flash files saved in .spl (Flash 1.0) format" because Shockwave Flash 2.0 covers both MIME types.

To Table of Contents Back to Previous document Forward to next document