|MySQL Conference and Expo April 14-17, 2008, Santa Clara, CA|
Many web developers, myself included, have long mistrusted plug-ins -- and with good cause. By enabling proprietary file formats, plug-ins are by their nature antithetical to the open spirit of the Web. What's more, they often have significant limitations such as forcing content to appear in a box on the page or showing up as a broken icon if the plug-in hasn't been installed.
On the other hand, they are clearly far superior to HTML and dynamic HTML for a number of applications, multimedia being the most obvious. While some may continue to avoid the use of plug-ins, the most popular plug-ins -- such as Flash, QuickTime, and RealPlayer -- are just about as likely to be installed as any given browser version. And there are some things such as complex animation, video, and streaming audio that simply cannot be done in a browser without using a plug-in, so plug-ins are definitely here to stay.
Dealing with plug-ins
Because there are clearly times when it makes sense to use a plug-in, the question arises of how to deal with those who don't have the required plug-in installed. As Web developers, we have several choices. One option is to do nothing and simply serve the plug-in-dependent content. The trouble is that those that don't have the required plug-in will get a rather disturbing page with a broken plug-in icon where your beautiful multimedia should be.
Another option is to give visitors a choice between the plug-in version and the static HTML version of each page. Sometimes this may be the best choice, because it gives your visitors control over their experience. There are two problems, however. First of all, the choice itself interrupts a visitor's experience of the site. Second, it requires them to know which plug-ins they have installed. But why should they need to know? Many users don't know a plug-in from a spark plug.
The final and often best option, the one this script is designed to help with, is to check to see if each visitor has a given plug-in. If they do, you can go ahead and serve them the page with the plug-in embedded. If they don't, you can either serve a plain HTML version of the page, or point them to where they can download the necessary plug-in. (Since plug-in detection is not foolproof, as you'll see, you may also want to give visitors a choice at this point in case they do have the plug-in after all.)
The great advantage of plug-in detection is that it makes a much more seamless experience possible: Visitors only need to think about plug-ins (or even know such a thing exists) if they do not have one. Because plug-in detection is a notoriously tricky business, this script was written to make detection of the most common plug-ins as painless as possible.
The script's purpose
The script makes it easy to check for the existence of five of the most popular plug-ins: Apple's QuickTime, Macromedia's Flash and Shockwave for Director, Real Networks' RealPlayer, and Microsoft's Windows Media Player.
The script can also be used to redirect the browser to a new page if a given plug-in is (or is not) found.
Finally, the script reports whether detection is or is not possible.
Note: With some plug-ins, such as Flash and QuickTime, it is possible to check not only for the plug-in's existence, but for a specific version of the plug-in. However, version information is detected with greater ease and reliability from within a plug-in file. Further, that level of detail would add significantly to the size and complexity of this script. For these reasons I did not include version detection in this script.
The main challenge involves dealing with the different browsers and their various plug-in-detection capabilities. For example:
Netscape has a
On Windows, Internet Explorer has a
Until version 5, Internet Explorer on the Mac wasn't able to detect plug-ins at all, because there was neither a
Until very recently, there was no way to detect the QuickTime plug-in for Internet Explorer because it wasn't implemented as an ActiveX control. But more recent versions of QuickTime install a separate ActiveX control specifically to allow you to check for the existence of the QuickTime plug-in. Unfortunately, this requires a slightly different strategy than the other plug-ins, so the script includes a separate VBScript function called
instead of the older way:
Using the script
Copy the contents of the script between the
To check for a given plug-in, simply call one of the following functions, which will return a value of either "true" (if the plug-in is there) or "false" (if the plug-in is not there or could not be detected):
For example, to check for the existence of the QuickTime plug-in, you could do the following:
Once you know the plug-in is installed, there are several things you can do:
Finally, if you simply want to find out if detection is possible at all, do the following:
Nadav Savio is a contributing author for Apple Internet Developer.