Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Using JavaScript to Detect QuickTime

JavaScript can be used to detect the QuickTime plug-in in most versions of most browsers on Windows and the Mac OS. The details vary slightly by browser, but a single script can be written that works with all supported browsers.

Most browsers other than Internet Explorer for Windows (including Netscape, Mozilla-based browsers, Safari, and Internet Explorer for Macintosh version 5) support the JavaScript navigator.plugins.name array. You can detect whether the user has the QuickTime plug-in installed by testing this array for “QuickTime.”

Internet Explorer for Windows does not support the navigator.plugins array, but does allow you to use VBScript to detect whether the QuickTime plug-in is installed (by testing for the presence of the QuickTime ActiveX control).

Note: The QuickTime ActiveX control was introduced as part of QuickTime 4.1

The following listing contains an example script that detects the user’s operating system, browser type, and browser version, uses JavaScript to test for the QuickTime plug-in, uses VBScript to test for the QuickTime COM object, and detects users running older versions of Internet Explorer for Macintosh (making the assumption that these users also have QuickTime installed). This listing sets the variable haveqt either true or false.

Listing 1-1  Detecting QuickTime with JavaScript

 
<HEAD>
<TITLE>Test for QuickTime</TITLE>
 
<SCRIPT LANGUAGE="Javascript" type="text/javascript">
var haveqt = false;
</SCRIPT>
 
<SCRIPT LANGUAGE="VBScript">
On Error Resume Next
Set theObject =
CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")
On Error goto 0
If IsObject(theObject) Then
If theObject.IsQuickTimeAvailable(0) Then
haveqt = true
End If
End If
</SCRIPT>
 
<SCRIPT LANGUAGE="Javascript" type="text/javascript">
 
if (navigator.plugins) {
for (i=0; i < navigator.plugins.length; i++ ) {
if (navigator.plugins[i].name.indexOf
("QuickTime") >= 0)
{ haveqt = true; }
}
}
 
if ((navigator.appVersion.indexOf("Mac") > 0)
&& (navigator.appName.substring(0,9) == "Microsoft")
&& (parseInt(navigator.appVersion) < 5) )
{ haveqt = true; }
 
</SCRIPT>
</HEAD>

If you insert this JavaScript into the <HEAD> element of your HTML, you can test the variable haveqt for the presence of QuickTime. You might, for example, want to write the <EMBED> and <OBJECT> tags for a movie using JavaScript, writing the tags only if QuickTime is installed. Or you might want to redirect users without QuickTime to an alternate page.



< Previous PageNext Page > Hide TOC


Last updated: 2008-02-08




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice