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


Listing 23.4 MimeType.htm—JavaScript to Detect Locally Supported MIME types


<HTML>
<HEAD>
<TITLE>JavaScript MIME Types Check</TITLE>
</HEAD>
<BODY BGCOLOR=“#FFFFFF”>
<H1>JavaScript MIME Types Check</H1>
<HR>
<SCRIPT LANGUAGE=“JavaScript”>
<!-- Hide script from incompatible browsers -->
var i,n
n = navigator.mimeTypes.length
document.writeln(“The following MIME types are recognized:<P>”)
document.writeln(“<TABLE BORDER WIDTH=100%>”)
document.writeln(“<TR><TH COLSPAN=2>MIME Type</TH></TR>”)
document.writeln(“<TR><TH>Extensions</TH><TH>” +
   “Associated Plug-In (if any)</TH></TR>”)
for (i=0;i<n;i++)
   if (navigator.mimeTypes[i].enabledPlugin)
      document.writeln(“<TR><TD COLSPAN = 2><B>” +
         navigator.mimeTypes[i].type + “</B></TD></TR><TR><TD>” +
         navigator.mimeTypes[i].suffixes + “</TD><TD>” +
         navigator.mimeTypes[i].enabledPlugin.name + “</TD></TR>” )
   else
      document.writeln(“<TR><TD COLSPAN = 2><B>” +
         navigator.mimeTypes[i].type + “</B></TD></TR><TR><TD>” +
         navigator.mimeTypes[i].suffixes + “</TD><TD></TD></TR>” )
document.writeln(“</TABLE>”)
//   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.6  JavaScript can use the navigator.mimeTypes to determine the built-in MIME type support in the client Web browser.

Calling Plug-in Functions from JavaScript

For plug-in variables and methods to be accessible from JavaScript and Java applets, the plug-in must be LiveConnect compatible and associated with the netscape.plugin.Plugin Java class. If that is true, the plug-in variables and methods are available to JavaScript—in much the same way as the public variables and methods of Java applets are available.

JavaScript gives you two ways to access and control compatible plug-ins active in the Web environment. Similar to Java applets, the first is to use the NAME attribute of the <EMBED> tag to give a name to the embedded document. This enables the plug-ins’ functions to be accessed through the document object. If NAME=myenvoydoc is used with the <EMBED> tag to embed an Envoy document using the Envoy Plug-In Viewer, for example, you can access the viewer functions by using the document.myenvoydoc object.

It is possible to access plug-ins even if they are not named by using the embeds array of the document object. If an Envoy document is the first embedded document in the Web page, it can be accessed with document.embeds[0].

Figure 23.7 shows a simple example from the Netscape site of an HTML forms button that calls a JavaScript used to start the LiveAudio plug-in. The plug-in content is included in the Web page with the following HTML code:

<EMBED SRC=“suspens1.wav”
       HIDDEN=TRUE
       NAME=“Mysound”
       MASTERSOUND
       AUTOSTART=yes
       LOOP=NO
>

The JavaScript used to interface with the plug-in is

<input type=“button” value=“Play Sound” onClick=“document.Mysound.play(false)”>
<input type=“button” value=“Stop Sound” onClick=“document.Mysound.stop()”>

This example can be found at the following location on the Netscape site: http://developer.netscape.com:80/docs/technote/javascript/liveconnect/js_plugin.html.


FIGURE 23.7  HTML forms and JavaScripts are the perfect combination for creating user interfaces to Java applets and plug-ins.

Using JavaScript to Control the Shockwave Flash Player

One of the more popular types of multimedia content to include in a Web page is content created for Shockwave using one of Macromedia’s applications, such as Macromedia Director, Authorware, or FreeHand. Typically, Shockwave content is displayed using the Macromedia Shockwave Flash Player. This free player gives the user a number of options for viewing the content.

You can also make use of the methods of the Shockwave Flash Player to control precisely how your Shockwave for Director movie, for example, appears to your users. This is done by including JavaScripts that respond to timers or user input to control the display of your movie through the Flash Player. Following is a list of some of the more useful methods available from the Shockwave Flash Player:

  GotoFrame(frame_number)—Moves the player to the specified frame number.
  IsPlaying()—Returns TRUE or FALSE, depending on whether the movie is currently playing.
  Pan(x,y,mode)—If the movie has been zoomed in, this method enables you to pan right or left, up or down.
  PercentLoaded()—This method returns the percentage of the movie that has been downloaded so far.
  Play()—Starts playing the movie through the player.
  Rewind()—Rewinds the movie.
  SetZoomRect(left,top,right,bottom)—Zooms in on a rectangular area of the movie.
  StopPlay()—Stops the movie.
  Zoom(percent)—Zooms the movie by the specified percentage.

For more information on Macromedia Shockwave, you can visit their Web site at http://www.macromedia.com. You can find more specific information on controlling the Flash Player in your Web pages at http://www.macromedia.com/support/flash/.


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.