spacer

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

home / experts / javascript / column20


Plug-ins and Plugin objects

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

A plug-in is a software module which is installed on the user's machine for the purpose of displaying specialized types of data embedded in Web pages. If you're running Navigator, you can discover which plug-ins are installed by selecting the "About Plug-ins" option from the "Help" menu. There are hundreds of plug-ins available on the Web, for displaying audio, video, 3D/VRML, and more. An audio plug-in must be installed in order to play an audio file, unless the browser is equipped with built-in audio support. When you embed sound in your Web pages, it is important to check that the required plug-in is indeed installed on the user's machine. You cannot take it for granted, as some users install their browsers without plug-ins. If you don't take the right measures to avoid displaying audio when the necessary plug-in is missing, the browser will display an alert.

Some versions of Netscape Navigator 3.0x and 4.0x come with the LiveAudio plug-in, while some versions of Microsoft Internet Explorer 4.0x include the ActiveMovie Control, which is required in order to play sounds.

In Navigator, an installed plug-in is represented by a JavaScript Plugin object. A Plugin object stores all available information about the relevant plug-in and MIME types supported by that plug-in. The following table summarizes the properties of a Plugin object:

PropertyDescription
nameThe name of the plug-in.
descriptionA short description of the plug-in.
filenameThe name of plug-in's file on disk.
lengthThe length of the plug-in's array of MimeType objects. In other words, this property reflects the number of MIME types supported by the plug-in.

All Plugin objects can be accessed through the navigator.plugins array. An individual Plugin object can be accessed through the plugins array. For example, plugins[0] is a Plugin object, representing one of the browser's plug-ins. Remember that the navigator.plugins array (and the Plugin object) is only supported by Navigator. In Internet Explorer, the navigator.plugins property is an empty array. Plugin objects can also be referenced by their name. The LiveAudio plugin object, for example, is plugins["LiveAudio"]. The properties of LiveAudio plugin can be found by printing the following variables:

<SCRIPT LANGUAGE="JavaScript1.1">
<!--

if (navigator.plugins["LiveAudio"]) {
  var liveAudioName = navigator.plugins["LiveAudio"].name;
  var liveAudioDescription = navigator.plugins["LiveAudio"].description;
  var liveAudioFilename = navigator.plugins["LiveAudio"].filename;
  var liveAudioMimeCount = navigator.plugins["LiveAudio"].length;

  document.write("name = ", liveAudioName, "<BR>",
    "description = ", liveAudioDescription, "<BR>",
    "filename = ", liveAudioFilename, "<BR>",
    "length = ", liveAudioMimeCount);
}

// -->
</SCRIPT>

For example, the script's output could be:

name = LiveAudio
description = Sound Player for Netscape Navigator, v.1.1.1513
filename = D:\PROGRAM FILES\NETSCAPE\COMMUNICATOR -->
4.04\PROGRAM\plugins\npaudio.dll
length = 9

The script looks very simple, but there are several important issues. First of all, notice that the LANGUAGE attribute is set to "JavaScript1.1". That is, the script is only executed if the browser is Internet Explorer 4.0x (and above) or Navigator 3.0x (and above). LiveAudio, Navigator's audio plug-in, is only installed in various versions of Navigator 3.0x and 4.0x. Furthermore, the navigator.plugins property is an empty collection in Internet Explorer 4.0x, so we can access its "properties," but none actually exist. The if statement, as explained in Column 6, Browser Compatibility, is used to check if an existing object features a specific property.

Let's take another look at the statements referring to the LiveAudio plug-in's Plugin properties:

var liveAudioName = navigator.plugins["LiveAudio"].name;
var liveAudioDescription = navigator.plugins["LiveAudio"].description;
var liveAudioFilename = navigator.plugins["LiveAudio"].filename;
var liveAudioMimeCount = navigator.plugins["LiveAudio"].length;

All four properties refer to the same parent object. Instead of specifying the object's entire path each time, we can assign its reference to a variable:

var liveAudio = navigator.plugins["LiveAudio"];
var liveAudioName = liveAudio.name;
var liveAudioDescription = liveAudio.description;
var liveAudioFilename = liveAudio.filename;
var liveAudioMimeCount = liveAudio.length;

Now suppose we want to find out what navigator.plugins[0] reflects. The following script segment shows how:

var liveAudioName = navigator.plugins[0].name;
var liveAudioDescription = navigator.plugins[0].description;
var liveAudioFilename = navigator.plugins[0].filename;
var liveAudioMimeCount = navigator.plugins[0].length;

Once again, you can assign navigator.plugins[0] to a variable. Note that each Plugin object also serves as an array containing one element for each MIME type supported by the plug-in module. The referencing schemes above apply to MIME types as well. You can reference them by name or by index. MIME types are covered extensively later in this column. The following code segment determines whether or not the LiveAudio plug-in supports "audio/wav" files:

if (navigator.plugins["LiveAudio"] && 
navigator.plugins["LiveAudio"]["audio/wav"])
  alert("supported")
else
  alert("not supported");

Notice that the script also checks if the LiveAudio plug-in exists, because accessing a property of an object that does not exist generates an error (as opposed to an unexisting property of an existing object). Once again, remember that navigator.plugins is an empty array in Internet Explorer, so the script would display "not supported."

http://www.internet.com

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

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
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
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
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior


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

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