home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


If you have developed an inline VRML scene to embed in a Web page, for instance, you might want to know whether the user has a plug-in installed that supports VRML. Then, a VRML world or a representative GIF image could be displayed, as appropriate, such as the following:

<SCRIPT LANGUAGE=“JavaScript”>
<!-- Hide script from incompatible browsers -->
var isVrmlSupported,VrmlPlugin
isVrmlSupported = navigator.mimeTypes[“x-world/x-vrml”]
if (isVrmlSupported)
   document.writeln(“<EMBED SRC=‘world.wrl’ HEIGHT=200 WIDTH=400>”)
else
   document.writeln(“<IMG SRC=‘world.gif’ HEIGHT=200 WIDTH=400>”)
//   Hide script from incompatible browsers -->
</SCRIPT>


NOTE:  As the next section shows, the <OBJECT> tag is the preferred method of including plug-in content for Internet Explorer; Navigator uses <EMBED>. Internet Explorer does, however, support the <EMBED> tag.

Including and Referencing Plug-in Objects

The first step in using plug-ins within a Web page is to include them in the first place. The recommended way to do this is to use the <OBJECT> tag; however, both Internet Explorer and Navigator support the <EMBED> tag as well. If you want to include plug-in content in a Web page that will work with browsers that support both tags, use something like the following, which shows an example using the Flash Player by Macromedia:

<OBJECT CLASSID=“clsid:D27CDB6E-AE6D-11cf-96B8-444553540000”
   ID=“objID” WIDTH=100 HEIGHT=100
   CODEBASE=“<http://active.macromedia.com/flash2/cabs/>
⇒swflash.cab#version=2,0,0,11”>
<PARAM NAME=“Movie” VALUE=“controls.swf”>
<EMBED NAME=“objID” MAYSCRIPT SRC=“controls.swf”
   WIDTH=100 HEIGHT=100
   PLUGINSPAGE=“<http://www.macromedia.com/shockwave/download/>
⇒index.cgi?P1_Prod_Version=ShockwaveFlash”>
</OBJECT>


NOTE:  Note that the preceding example actually is used to either call the Macromedia Flash ActiveX control or plug-in, depending on whether Internet Explorer or Navigator is used. You can use the same technique, however, to include plug-in content for each browser. You can read more about accessing and manipulating ActiveX controls later in this chapter.

This HTML code segment consists of the following tags:

  The <OBJECT> tag is used to include the plug-in content meant for Internet Explorer; its ID attribute gives it the name that will be used to script it.
  The <PARAM> tag (there can be as many of them as necessary) includes a NAME and a VALUE attribute used to configure the plug-in.
  The <EMBED> tag is included within the <OBJECT> container tag; this provides alternate content for browsers that do not understand the <OBJECT> tag. In this case, the plug-in content would be included either via the <OBJECT> or <EMBED> tag, but not both. The NAME attribute performs the same function as the ID attribute of the <OBJECT> tag—in this case, the SRC attribute.

Plug-ins included with the <OBJECT> and <EMBED> commands are also referenced differently. When included with the <OBJECT> tag, plug-in objects are members of the window object; those with <EMBED> are members of window.document.

Determining Which Plug-ins Are Installed

The navigator.plugins object has the following properties:

  description—A description of the plug-in, supplied by the plug-in itself
  filename—The filename on the disk in which the plug-in resides
  length—The number of elements in the navigator.plugins array
  name—The plug-in’s name

Listing 23.3 shows an example of a JavaScript that uses the navigator.plugins object to display the names of the installed plug-ins right on the Web page. You can place this JavaScript at the bottom of any Web page to display this information (see Figure 23.5).

Listing 23.3 PlugIn.htm—JavaScript to Detect Locally Installed Plug-ins


<HTML>
<HEAD>
<TITLE>JavaScript Plug-Ins Check</TITLE>
</HEAD>
<BODY BGCOLOR=“#FFFFFF”>
<H1>JavaScript Plug-Ins Check</H1>
<HR>
<SCRIPT LANGUAGE=“JavaScript”>
<!-- Hide script from incompatible browsers -->
var i,n
n = navigator.plugins.length
document.writeln(“This Web browser has “ + n + ” plug-ins installed:<P>”)
for (i=0;i<n;i++)
   document.writeln(navigator.plugins[i].name + “<BR>”)
//   Hide script from incompatible browsers -->
</SCRIPT>
<HR>
<ADDRESS>
Jim O’Donnell, <A HREF=“mailto:odonnj@rpi.edu”>odonnj@rpi.edu</A>
</ADDRESS>
</BODY>
</HTML>


FIGURE 23.5  The navigator.plugins object enables you to use JavaScript to determine whether a plug-in is installed.

Client-Supported MIME Types

The navigator.mimeTypes object is similar to the navigator.plugins object and can be used to determine supported MIME types at the client. It has the following properties:

  description—A description of the MIME type
  enabledPlugin—A reference to the particular navigator.plugins object that handles this MIME type
  length—The number of elements in the navigator.mimeTypes array
  suffixes—A string listing the filename extensions, separated by commas, for this MIME type
  type—The MIME type name (for example, x-world/x-vrml)

Listing 23.4 shows an HTML document that contains a JavaScript that displays all the client-supported MIME types in an HTML table. Along with the MIME type, the supported file extensions are shown, as well as the name of the associated plug-in, if any (see Figure 23.6).


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.