May 11, 2001 - Checking for Flash on Win IE
May 11, 2001 Checking for Flash on Win IE Tips: May 2001
Yehuda Shiran, Ph.D.
|
One of these tiny details is checking that the Flash player is installed. On a Win Internet Explorer system, Flash is implemented by an ActiveX control. The easiest way to check for Flash on such a system is by VBScript. Here is the code:
<SCRIPT LANGUAGE=VBScript>
Function Flash_checkForActiveX
Dim hasPlayer, playerversion, minVersion
minVersion = 4
hasPlayer = false
playerversion = 10
Do While playerversion >= minVersion
On Error Resume Next
hasPlayer = (IsObject(CreateObject(
"ShockwaveFlash.ShockwaveFlash." & playerversion & "")))
If hasPlayer = true Then Exit Do
playerversion = playerversion - 1
Loop
Flash_checkForActiveX = hasPlayer
End Function
</SCRIPT>
And here is the conditional version of the same script. It checks first that the browser is supported, as well as that the system is WIN IE. Only then it writes our the VBScript to check that the player is installed and its version is supported. Here is the code:
if(supportedBrowser && winIEpass) {
document.write(
'<script language=VBScript>' + '\n' +
'Function Flash_checkForActiveX()' + '\n' +
'Dim hasPlayer, playerversion' + '\n' +
'hasPlayer = false' + '\n' +
'playerversion = 10' + '\n' +
'Do While playerversion >= minPlayer' + '\n' +
'On Error Resume Next' + '\n' +
'hasPlayer = (IsObject(CreateObject(\
"ShockwaveFlash.ShockwaveFlash.\" & playerversion & \"\")))' + '\n' +
'If hasPlayer = true Then Exit Do' + '\n' +
'playerversion = playerversion - 1' + '\n' +
'Loop' + '\n' +
'Flash_checkForActiveX = hasPlayer' + '\n' +
'End Function' + '\n' +
'<\/script>'
);
}