Detecting Shockwave Player using JavaScript
Issue
Developers using JavaScript or VBScript to detect the presence of the Shockwave Player will need to make sure the method works for Shockwave Player 10.
Reason
The version number for Shockwave Player for Director MX 2004 is 10. JavaScript routines that check only the first numeral of the version string will need to be updated to detect Shockwave Player v10. Otherwise, the version returned will be 1, and the user will be prompted to download a new Player version even though they may not need to.
Solution
Shockwave Player detection can be accomplished a number of different ways. The method you choose may differ according to the point you are at in the workflow.
Replace existing detection template
This method is appropriate for any new Director projects and will allow you to publish HTML files to house your Shockwave Player files that will perform detection using JavaScript and VBScript. The replacement templates are available in the js_detect.zip file, available from this TechNote.
Add JavaScript code to existing templates or to existing HTML files
This method is appropriate for existing files you don't want to re-publish, and you can use this approach to edit existing templates for older versions. The script below uses JavaScript and VBScript to detect the Shockwave plug-in or ActiveX control. This code detects any version of Shockwave.
<SCRIPT LANGUAGE=JavaScript><!-- var tMajorVersion = 10; var tMinorVersion = 1; var tShockwaveFound = 0; if (navigator.mimeTypes && navigator.mimeTypes["application/x-director"]&& navigator.mimeTypes["application/x-director"].enabledPlugin) { if (navigator.plugins && navigator.plugins["Shockwave for Director"]&& (tVersionIndex = navigator.plugins["Shockwave for Director"].description.indexOf(".")) != - 1) { var tMajorVersionString = navigator.plugins["Shockwave for Director"].description.substring(tVersionIndex-2, tVersionIndex); var tMinorVersionString = navigator.plugins["Shockwave for Director"].description.substring(tVersionIndex+1, tVersionIndex+2); if (parseInt(tMajorVersionString) >= tMajorVersion) { if (tMinorVersion > 0) { if (parseInt(tMinorVersionString) >= tMinorVersion) { tShockwaveFound = 1; } } else { tShockwaveFound = 1; } } } } else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0 )) { var tVersionString = ""; document.write('<SCRIPT LANGUAGE=VBScript\> \n'); document.write('on error resume next \n'); document.write('set tSWControl = CreateObject("SWCtl.SWCtl") \n'); document.write('if IsObject(tSWControl) then \n'); document.write('tVersionString = tSWControl.ShockwaveVersion("") \n'); document.write('end if'); document.write('</SCRIPT\> \n'); if (tVersionString != "") { tVersionIndex = tVersionString.indexOf(".") var tMajorVersionString = tVersionString.substring(tVersionIndex-2, tVersionIndex); var tMinorVersionString = tVersionString.substring(tVersionIndex+1, tVersionIndex+2); if (parseInt(tMajorVersionString) >= tMajorVersion) { if (tMinorVersion > 0) { if (parseInt(tMinorVersionString) >= tMinorVersion) { tShockwaveFound = 1; } } else { tShockwaveFound = 1; } } } } if ( tShockwaveFound ) { document.write('<OBJECT classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000"'); document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=10,1,0,11"'); document.write(' ID=$TI WIDTH=$WI HEIGHT=$HE>'); document.write('<PARAM NAME=src VALUE="$MO">'); document.write('<PARAM NAME=swStretchStyle VALUE=$SS>'); document.write('<PARAM NAME=swRemote VALUE="'); document.write("$PR"); document.write('">\n'); document.write('<EMBED SRC="$MO"'); document.write(' $PE WIDTH=$WI HEIGHT=$HE swStretchStyle=$SS '); document.write('swRemote="'); document.write("$PR"); document.write('"'); document.write(' TYPE="application/x-director" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveDirector">'); document.write('</EMBED>'); document.write('</OBJECT>'); } else if (!(navigator.appName && navigator.appName.indexOf("Netscape")>=0 && navigator.appVersion.indexOf("2.")>=0)){ document.write('A newer version of Shockwave must be installed to display this content. Please update your Shockwave installation.'); } //--></SCRIPT>
Use function in external JavaScript file
This method is appropriate when developers want to call a function that will detect and return the Shockwave Player version. This may be useful, for example, if developers want site visitors to see what version number they have. The getSWVersion.js file included in the js_detect.zip file.
Files available in the js_detect.zip download
Included with this TechNote is a .ZIP file, which contains two detection templates and a JavaScript file. Download this ZIP file and open it using an unzip utility. The files included in this ZIP and the file's purpose are listed below:
- MX04_Detect.htm This file replaces the Detect.html file for Director MX 2004, the default location is: C:\Program Files\Macromedia\Director MX 2004\Configuration\Publish Templates\Detect.html
- MX_Detect.htm This file replaces the Detect.html file for Director MX, the default location is: C:\Program Files\Macromedia\Director MX 2004\Configuration\Publish Templates\MX Templates\Detect.html
- getSWVersion.js This file can be used in any website and includes a function that returns the installed Shockwave Player version.
There is one detection template provided for Director MX and one for Director MX 2004. Replace the existing Detect.html file available as part of the Director installation. To do this, make sure to change the name of the appropriate file when extracted to "Detect.html", thus replacing the old file. After replacing this file, your template will be updated under your Shockwave publish settings.
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
