Java Reference
In-Depth Information
recognize both the <object/> and <embed/> elements and get confused — particularly over the id
values, because both have the same id of audioPlayer.
Beneath the <object/> element is a form with two buttons. The fi rst has an id and name value of
buttonPlay and executes the buttonPlay_onclick() function when the user clicks it. The second
button is called buttonStop, and it executes the buttonStop_onclick() function when clicked.
Determining Plug-in/ActiveX Control Availability
You want to make sure that users without QuickTime don't see error messages when they attempt to
use the scripted controls. In this exercise, let's disable the buttons used to control the audio playback.
Add the following <script/> element to the HTML page's head; it defi nes a function to do disable the
buttons and attaches it to the window object's onload event handler.
<script type=”text/javascript”>
function window_onload() {
var plugInInstalled = false;
if (!window.ActiveXObject) {
var pluginsLength = navigator.plugins.length;
for (var i = 0; i < pluginsLength; i++) {
var pluginName = navigator.plugins[i].name.toLowerCase();
if (pluginName.indexOf(“quicktime”) > -1) {
plugInInstalled = true;
break;
}
}
} else {
if (document.audioPlayer.readyState == 4) {
plugInInstalled = true;
}
}
if (!plugInInstalled) {
document.forms[0].buttonPlay.disabled = true;
document.forms[0].buttonStop.disabled = true;
alert(“You need Quicktime to play the audio file!”);
}
}
onload = window_onload;
</script>
In the window_onload() function, you fi rst defi ne a variable, plugInInstalled, and initialize it as
false. Next, since checking for plug-ins or controls is browser-dependent, you check to see if this is a
Microsoft browser. A simple check for the ActiveXObject property of the window object will suffi ce.
If the browser is a non-IE browser, use a for loop to iterate over the navigator object's plugins collec-
tion, checking each installed plug-in's name for the word quicktime (note that you're checking the lower-
case version of the word; this is to provide a more accurate search). Set the variable plugInInstalled to
true and break out of the for loop if this name is found.
Search WWH ::




Custom Search