Java Reference
In-Depth Information
The fi rst line of JavaScript code declares the plugInInstalled variable; this is the same variable
that was declared within the window_onload() function in the original example. Verify that the
user has the ability to use the QuickTime plug-in in the window's onload event handler, which calls
the window_onload() function.
Because the support for plug-ins is different between IE and other browsers, the means of checking for
plug-ins is also different. For Firefox, Safari, Chrome, and Opera, go through the navigator object's
plugins collection and check each installed plug-in for the name quicktime; if it's found, you know
the user has the QuickTime player installed.
With IE, simply use the ActiveX control's readyState property to see if it's installed and initialized
correctly.
To play the sounds, a function called play() is defi ned whose parameter is the fi le name of the sound fi le
to be played. This function checks whether or not the QuickTime plug-in or ActiveX control is installed.
function play(fileName)
{
if (plugInInstalled)
{
document.audioPlayer.SetURL(fileName);
document.audioPlayer.Play();
}
else
{
alert(“You must have QuickTime installed to play this file.”);
}
return false;
}
If it is installed, then the function makes use of the QuickTime player's SetURL() method to set the
sound fi le to be played and the Play() method to start playing the clip. If it isn't installed, an alert box
tells the user they must have QuickTime installed in order to hear the sound fi le.
You have used different sounds for each link by simply specifying a different fi le name each time as the
parameter for the play() function. The onclick event handler starts playing the sound when you click
the link.
<a href=”#” onclick=”return play('sound1.mp3')”>Sound 1</a>
Chapter 14
Exercise 1 Question
Extend the HttpRequest module to include synchronous requests in addition to the asynchronous
requests the module already makes. You'll have to make some adjustments to your code to incorporate
this functionality. (Hint: Create an async property for the module.)
Search WWH ::




Custom Search