Web DevCenter
oreilly.comSafari Books Online.Conferences.
MySQL Conference and Expo April 14-17, 2008, Santa Clara, CA

Sponsored Developer Resources

Web Columns
Adobe GoLive
Essential JavaScript

Web Topics
All Articles
Scripting Languages

Atom 1.0 Feed RSS 1.0 Feed RSS 2.0 Feed

Learning Lab

O'Reilly Network Script Library -- Javascript

Plug-in Detection

Language: JavaScript

Download the files for this script (zip format)

The script makes it easy to check for the existence of 5 commonly-used 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 that for 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, version detection is not included in this script.

See the article, Plug-in Detection with JavaScript for a full discussion of this script. This script originally appeared on Apple Internet Developer site.


Copy the contents of the script between the <HEAD> and </HEAD> tags in your document. (Since we're using multiple <SCRIPT> blocks, it would require two separate .js files and wouldn't work for Netscape 3, so it makes more sense to just include the script in your document.)

To check for a given plug-in, simply call one of the following functions, which 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):

  • detectQuickTime()
  • detectFlash()
  • detectDirector()
  • detectWindowsMedia()
  • detectReal()

For example, to check for the existence of the QuickTime plug-in, you could do the following:

var quickTimeIsInstalled = detectQuickTime();
  alert('You have the QuickTime plug-in.');

Once you know if the plug-in is installed, there are several things you can do:

  • You can use JavaScript to write out a message stating the plug-in wasn't found. You could also use JavaScript to write out the <OBJECT> and/or <EMBED> tags that pull the plug-in content if the plug-in was found).

  • You can put the detection code in a frameset and use JavaScript to write out different frame sources depending on whether or not the plug-in was found.

  • Finally, you can use JavaScript to redirect the browser to a new page depending on whether or not the plug-in was found. The script makes it easy to do this redirection:

    • If you pass the function a URL, it will redirect to that URL if the plug-in is not found: detectQuickTime('non_plugin_page.html');
    • If, instead, you want to redirect if the plug-in is found, pass the function both a URL and the word true: detectQuickTime('plugin_found_page.html', true)

Finally, if you simply want to find out if detection is possible at all, do the following:

var ableToDetect = canDetectPlugins();
  alert('It is possible to check for plug-ins.');