Detect plugins presenceTag(s): Varia
There is no portable way to do it on all browsers. On Netscape, it's very straightforward. All we need is to check plugins property.
For example, to detect if the RealPlayer is installed :
<SCRIPT>
numPlugins = navigator.plugins.length;
for (i = 0; i < numPlugins; i++)
{
plugin = navigator.plugins[i];
if (plugin.name.substring(0,10)=="RealPlayer")
{
alert("You have the RealPlayer Plug-in installed!")
}
}
</SCRIPT>
With IE, we try to instanciate to corresponding COM object. If the object is null then we assume that the plugin is missing. Again for the RealPlayer :
<SCRIPT LANGUAGE="VBScript">
on error resume next
RealPlayerG2 =
not IsNull(CreateObject("rmocx.RealPlayer G2 Control"))
RealPlayer5 =
not IsNull(CreateObject
("RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)"))
RealPlayer4 =
not IsNull(CreateObject
("RealVideo.RealVideo(tm) ActiveX Control (32-bit)"))
if (RealPlayerG2 or RealPlayer5 or RealPlayer4) then
document.write "RealPlayer Ok"
else
document.write "RealPlayer not found"
end if
</SCRIPT>
<SCRIPT LANGUAGE="Javascript">
<!--
// detection for Netscape
var useFlash = navigator.mimeTypes &&
navigator.mimeTypes["application/x-shockwave-flash"] &&
navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
//-->
</SCRIPT>
<SCRIPT LANGUAGE="VBScript">
<!--
' detection for IE
On error resume next
useFlash = NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash"))
//-->
</SCRIPT>
...
<SCRIPT LANGUAGE="Javascript">
<!--
if ( useFlash ) {
document.write('<CENTER><embed SRC="mything.swf"
WIDTH="530" HEIGHT="523" align="center" LOOP="true"
QUALITY="high"></center>');
}
else {
document.write('Non-Shockwave');
}
//-->
</SCRIPT>
Let's say we want to detect if the ActiveX object for Acrobat Reader is installed from IE. Start RegEdit, go to HKEY_LOCAL_MACHINE\Software\CLASSES\ and locate the entries for the file extension (pdf) used by Acrobat. The first key value gives the ActiveX object to use with IE, AcroExch.Document, and the second the MIME type to be used with Netscape.
<SCRIPT LANGUAGE="Javascript">
<!--
// detection for Netscape
var useAcrobat = navigator.mimeTypes &&
navigator.mimeTypes["application/pdf"]
//-->
</SCRIPT>
...
<SCRIPT LANGUAGE="VBScript">
<!--
on error resume next
useAcrobat = not IsNull(CreateObject("AcroExch.Document"))
' can be CreateObject("PDF.PdfCtrl.1") too!
//-->
</SCRIPT>
<SCRIPT>
<!--
if (useAcrobat)
document.write("Acrobat reader ok");
else
document.write("Acrobat reader not found");
//-->
</SCRIPT>
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com