Main Page

Cross-browser detection

Plugin
Version-Independent Version-Specific Names
Name
Real Player G2
rmocx.RealPlayer rmocx.RealPlayer G2 Control.1
G2 Control
Quicktime
Quicktime.Quicktime Quicktime.Quicktime.1
Windows Media Player
WMPlayer.OCX
WMPlayer.OCX.7
WMPlayer.OCX.8
To make use of the ActiveX control name, try to create the given object using an
ActiveXObject
. For
example:
function detectFlashInIE() {
try {
new ActiveXObject(“ShockwaveFlash.ShockwaveFlash”);
return true;
} catch (oError) {
return false;
}
}
This function’s purpose is to determine if the Flash Player is installed. To do so, it tries to create the
ActiveXObject
with the name
ShockwaveFlash.ShockwaveFlash
. If this is successful, the next line
executes and the function returns
true
. If the object can’t be created, the error is caught and the function
returns
false
. This same basic algorithm can be used for any plugin with an ActiveX wrapper.
Cross-browser detection
Unfortunately, you have no easy way to establish cross-browser plugin detection in a generic way. In
order to accurately detect if a plugin is available, you must know both the MIME type and the ActiveX
control name. Most of the time, developers just create specific detection functions that include both
pieces of information, such as the following:
function detectFlash() {
if (navigator.mimeTypes.length > 0) {
return navigator.mimeTypes[“application/x-shockwave-flash”].enabledPlugin
!= null;
} else if (window.ActiveXObject) {
try {
new ActiveXObject(“ShockwaveFlash.ShockwaveFlash”);
return true;
} catch (oError) {
return false;
}
This method of plugin detection works only in Internet Explorer 5.0 and higher for
Windows.
542
Chapter 18
21_579088 ch18.qxd 3/28/05 11:43 AM Page 542


JavaScript EditorFree JavaScript Editor     Ajax Editor


©