spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column20


MIME Types

Developer News
Metasploit 3.2 Offers More 'Evil Deeds'
'Thank You Apple. Seriously.'
The Buzz: BlackBerry App Store Seen Next

Navigator 3.0x and 4.0x support the MimeType object (Internet Explorer 4.0x doesn't). A MimeType object can be an element of the navigator.mimeTypes array:

navigator.mimeTypes[index]

where index is either an integer or a string containing the desired MIME type. For example, you can reference the "audio/wav" MimeType object as follows:

navigator.mimeTypes["audio/wav"]

A MimeType object can also be a property of a specific Plugin object:

navigator.plugins["LiveAudio"][index]

where index is either an integer or a string containing the MIME type. For example, you can reference the "audio/wav" MimeType via the LiveAudio Plugin object as follows:

navigator.plugins["LiveAudio"]["audio/wav"]

The following table summarizes the properties of a MimeType object:

Property Description
type The name of the MIME type.
description A description of the MIME type.
suffixes A string containing the MIME type's possible extensions. For example: "jpeg, jpg, jpe, jpv, vbs, jpegv".
enabledPlugin The Plugin object that can display data of the MIME type. enabledPlugin is null when there is no plug-in to display data of the specificied MIME type format.

The following example prints all MIME types supported by the browser. We extract the number of MIME types from the navigator.mimeTypes object's length property. The loop generates a table row for each MIME type:

document.write("<TABLE BORDER='1' CELLSPACING='0' CELLPADDING='3'>");
for (var i = 0; i < navigator.mimeTypes.length ; i++) {
  document.writeln("<TR VALIGN='top'><TD>", i, "</TD>",
  "<TD>", navigator.mimeTypes[i].type, "</TD>",
  "<TD>", navigator.mimeTypes[i].description, "</TD>",
  "<TD>")
  if (navigator.mimeTypes[i].suffixes != "")
    document.write(navigator.mimeTypes[i].suffixes)
  else
    document.write(navigator.mimeTypes[i].suffixes + " * ");
  document.write("</TD><TD>");
  if (navigator.mimeTypes[i].enabledPlugin)
    document.write(navigator.mimeTypes[i].enabledPlugin.name);
  else
    document.write("None");
  document.write("</TD><TR>");
}
document.write("</TABLE>");

Here is a sample output generated by Navigator 3.0x or 4.0x:

0model/vrmlVRML Worlds wrl, wrzCosmo Player 1.0
1x-world/x-vrmlVRML Worlds wrl, wrz Cosmo Player 1.0
2audio/x-liveaudioStreaming Audio Metafiles lamNetscape Media Player
3audio/x-midiMIDI mid, midiLiveAudio
4audio/midiMIDI mid, midiLiveAudio
5audio/nspaudioNetscape Packetized Audiola, lmaLiveAudio
6audio/x-nspaudioNetscape Packetized Audiola, lmaLiveAudio
7video/msvideoVideo for Windows aviNPAVI32 Dynamic Link Library

Since Navigator cannot handle hundred line tables, we have restricted the printout to the first few MIME types (Navigator supports a few hundreds MIME types!). The script also prints a * character if the suffixes property is an empty string

It's important to understand the relationship between plug-ins (software modules) and MIME types. enabledPlugin is the plug-in configured for the specified MIME type. Each MIME type can be supported by multiple plug-ins, and each plug-in can handle multiple MIME types, but only one plug-in can be activated for a single MIME type. The enabledPlugin property is a reference to a Plugin object which represents the plug-in that handles the given MIME type.

Audio support on the Web is quite complicated. Navigator 3.0x and above can play embedded tracks provided that the LiveAudio plug-in is installed. Internet Explorer 4.0x and above can can play audio if the ActiveMovie Control is installed (it comes pre-packaged with Windows 95, but can also be downloaded for other platforms along with the browser). Note that many other plug-ins, for both browsers, support audio. However, since we are interested in JavaScript-enabled sound implementations, we will stick with the default LiveAudio plug-in (Navigator) and the Active Movie Control (Internet Explorer).


var NSsound =
  navigator.plugins && navigator.plugins["LiveAudio"] && navigator.javaEnabled();
var IEsound = navigator.plugins && document.all;
var audioEnabled = NSsound || IEsound;

We check if Navigator supports sound by verifying that plugins arrays exists and one of the supported plug-ins is "LiveAudio". On Explorer, it's enough to check that the platform is Windows 95 (plugins array exists), and the its version is 4.0x or above (document.all exists).

http://www.internet.com



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview · Controllers: Programming Application Logic - Part 2 · How to Use JavaScript to Validate Form Data
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Choosing the Right Online Backup Provider · Mother Avaya Nurtures Her Technology Partners · Software as a Service a Winning Model for Hotspot Provider


Created: May 31, 1998
Revised: May 31, 1998

URL: http://www.webreference.com/js/column20/mimetypes.html