Java Reference
In-Depth Information
Length
Name
Description
File Name
Figure 13-3
If the Flash plug-in is not installed,
navigator.plugins[“Shockwave
Flash”]
will be
undefined
,
which JavaScript considers to be
false
, thereby causing the
else
statement to execute. If Flash is installed,
navigator.plugins[“Shockwave
Flash”]
will return the Flash
Plugin
object, which JavaScript treats
as
true
, and the main
if
statement will execute.
The problem with this method of detection is that the name given to a plug-in may vary from operating
system to operating system. For example, the name of the Windows XP version of the plug-in may vary
from the name of the Mac version, which in turn may vary from the name of the Linux version. Some
plug-ins, such as RealPlayer, will not work reliably at all with this detection method, because the name
is not simply RealPlayer but something that contains the word “RealPlayer.”
An alternative method for determining whether a plug-in is installed is to loop through the
plugins[]
array and check each
name
for certain keywords. If you fi nd them, you can assume that the control is
installed. For example, to check for QuickTime, you may use the following:
var pluginsLength = navigator.plugins.length;
for (var i = 0; i < pluginslength; plugInCounter++)
{
var name = navigator.plugins[i].name.toLowerCase();
if (name.indexOf(“quicktime”) > -1)
{
alert(“QuickTime is installed”);