Plugin detection
There have been a lot of attempts to detect all kinds of plug-ins, but they all require
a huge amount of javascript hacking to deal with the different browsers and plug-ins. In
this article I will show how to incorporate a plug-in detector with a few lines of
javascript code by using the javascript library I've developed.
If you are interested in how the detection works and if you like to enhance the library
with detection of other plug-ins I will show you that too. But first let's see what we can
detect from javascript (and a little VBScript) by going the next page: detector.htm
If you've a lot of plug-ins installed this might take a little time in Netscape.
How does it all work?
As you can see there are quite a number of things that can be detected, but it requires
some filtering to see to make it more accessible.
Detection in Internet Explorer seems a little harder than detection in Netscape
Navigator, because IE doens't have the plugins object. But in IE we have VBScript and this
is much powerfuller in working with ActiveX controls (most of the plugins are ActiveX
controls) than javascript.
Now I've seen most people that tried to detect plugins inside IE by writing an object tag
with the class id of the plugin the wanted to detect and then see if the written object
was accessible. It can be done much easier by calling a VBScript function from javascript.
In VBScript we can use the boolean IsObject() function together with the CreateObject(ClassID)
function. This way we have a clean and simple way to detect all kinds of ActiveX controls
that are installed on the users system.
I put together an object oriented detection library with two objects in it:
Is object This is an object that I picked
up from a browser sniffer article by Netscape. It can detect the internetbrowser an the OS
of your visitor.
Caps object. This object can be used to
detect what capabilities the browser of your visitor has. It handles the differences
between the specific browsers.
Including vrml detection in your pages
You can include VRML plug-in detection by following these simple steps.
| 1. |
Download the detection library: detection.js |
| 2. |
Include the following piece of javascript code inside the header of your page:
<script
language="Javascript" src="detection.js"></script>
<script language="Javascript">
<!--
var is;
var caps;
var isIE3Mac = false;
if ((navigator.appVersion.indexOf("Mac")!=-1) &&
(navigator.userAgent.indexOf("MSIE")!=-1)
&& (parseInt(navigator.appVersion)==3))
isIE3Mac = true;
else
{
is = new Is();
caps = new Caps();
}
//-->
</script>
|
| 3. |
Inside your code you can now use the is object and the caps object
for recognizing the specifics of your visitor's browser and it's capabilities.
For example use caps.vrml to detect if your visitor has a VRML browser installed.
Take a look at this example that dumps al
variables and their values. |
Forcing to use a specific browser
Inside Internet Explorer we can force that a specific plug-in has to be used for
viewing the VRML world. We do this by writing the <OBJECT> tag and using that
ClassID of the plug-in you want to be used.
Take a look at this example or download the zipped example.
Remember that this will not work in Nescape Navigator, because we need the <EMBED>
tag there.
If you want to learn how you can find out the ClassID of an object look at the section
below.
Extending the detection library
If you want to extend the library so it can detect other plug-ins you will have to do
the following:
| 1. |
You will need Netscape Navigator for finding the correct plug-in name |
| 2. |
Install the plug-in you want to detect if you haven't done that before.Be sure
you install the plug-in for Netscape Navigator and Internet Explorer. |
| 3. |
For detection in Netscape Navigator use the plug-in dump in detector.htm to find the name of the plug-in you installed.
You can copy and paste the string behind currentPlugin.name into a new detection variable
inside the caps object.
For example the Blaxxun browser can be detected with "blaxxun Contact (blaxxun
CCpro) Version 4.300"
If we want a version independent detection of the Blaxxun browser we will have to
look for a substring without the version number. |
| 4. |
For finding the ClassId (or the more readable ClassName) of an activeX control
you will need the OLE-COM Viewer. This is a tool that comes with Microsoft Visual Studio,
but can be downloaded also from the following location: http://www.microsoft.com/com/resources/oleview.asp |
| 5. |
If you start up the COM viewer you will see something like the screenshot
below.
On the left side you will find different categories of COM-objects. In general you
can find plug-ins for Internet Explorer under the "Controls that are safely
scriptable" tab. Sometimes you will not be able to find the plug-in you installed. In
that case take a look under "Controls" and look if you can find it there.
In the right side pane you will find a lot of information about the specific
control. You can find the ClassID that you can use to detect the control, but I prefer to
use the string behind ProgID.
|
| 6. |
Inside in the Caps object you can add a variable for detecting the plug-in as
follows:this.blaxxun =
(NAVDetectObject("blaxxun Contact (blaxxun CCpro)
Version 4.300"] ||
IEDetectObject("blaxxunCC3D.blaxxunCC3D.1")) ? true:false; |
| 7. |
No you can use the caps object the following way: if (Caps.blaxxun) document.write("You have the Blaxxun browser
installed");
else document.write("Could not find Blaxxun browser"); |
If you want to learn more about detection possibilities with javascript visit the
following websites:
The Ultimate JavaScript Client Sniffer, Version 3.0:
Determining Browser Vendor, Version, and Operating System With JavaScript
http://developer.netscape.com/docs/examples/javascript/browser_type.html
Browserspy on Gemal's psyched site
http://www.gemal.dk/browserspy/spy.html
|