Webmonkey
Powered by Atomz.com



Quick Reference:

• Javascript Code Library
HTML Cheatsheet
Special Characters
Color Codes
Browser Chart
Stylesheet Guide
Unix Guide
Glossary
Domain Registries

Reference   JavaScript Code Library

Plug-ins can be great if the person visiting your Web page has them installed. But if they're not installed, your user will be presented with a nasty-looking broken link icon. The trick is detecting whether or not they're installed before attempting to serve the plug-in content.

There's no perfect way to detect plug-ins, but the code on this page does it's damnedest to find out what's installed and what's not. There are two ways to use the code, both of which are explained below. Each will return a value of true (if the plug-in is there) or false (if it isn't there or if there's no way to tell). As Meghan's article points out, in some circumstances, plug-ins are just undetectable.

Usage: There are two ways to use WM_pluginbot — the easy (basic) way and the hard (advanced) way.

The Basic Way
If all you need to know is whether the user has some version of the Flash, QuickTime, Shockwave, or RealAudio plug-in, you can use the helper function WM_easyDetect and just tell it which plug-in to look for, like so:

WM_easyDetect('flash');
WM_easyDetect('quicktime');
WM_easyDetect('shockwave');
WM_easyDetect('realaudio');

You can then use this information to send the user to a different page depending on the result:

var hasFlash = WM_easyDetect('flash');
if(hasFlash) {
    window.location = 'flashversion.html';
} else {
    window.location = 'noflashversion.html';
}

If you're confused, take a look at the source code on the demo page.

The Advanced Way
If you need to check for a specific version (such as Flash version 4) or a plug-in other than these four, you'll need to use the main WM_pluginbot function and give it four arguments:

WM_pluginBot('pluginDescription' , 'fileExtension' , 'mimeType' , 'activeXControl' );

You can find out the pluginDescription by choosing Help/About Plug-ins in Netscape Navigator. Internet Explorer doesn't list plug-ins, so you'll have to use the name of the ActiveX control. Finding these names can be difficult; your best bet is to check with the plug-in manufacturer. You can leave the activeXControl blank (by inserting double quote marks), but this will return a value of false for Internet Explorer, even if the plug-in is installed.

This may seem a bit complicated (which is why we added the WM_easyDetect shortcut), but you can get a better idea of how it works by taking a look at the source code on the demo page.

License: Webmonkey Public License

Cut, paste, and enjoy!


Feedback  |  Help  |  About Us  |  Contribute  |  Jobs
Advertise  |  Privacy Statement  |  Terms and Conditions

Copyright © 1994-2000 Wired Digital Inc., a Lycos Network site. All rights reserved.