Javascript Flash Detection + CSS

Hello all, I’ve been using the Kirupa tuts for while but Ive got one that I need some help to adapt. I want to adapt the Kirupa flash detection script from this page: http://www.kirupa.com/developer/mx/detection.htm (near the bottom) whereby if the flash plugin is installed the flash element is shown, if not an image is used instead

*What I want to do is say - If the flash plugin is installed change the CSS background-color of an elements ID, if not installed change the CSS background-color of different elements ID.

-I figure it has something to do with the JavaScript ‘getElementbyID’ but being a bit of a Javascript muppet Ive only had limited success…

-I know for example that Javascript refers to the CSS properties slightly differently: http://codepunk.hardwar.org.uk/css2js.htm

This is what I have written BUT it works only in Firefox, not IE… how should I write this properly?

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<title>Flash Detection changing the CSS Style</title>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1” />
<SCRIPT LANGUAGE=JavaScript1.1>
<!–
function test() {
var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes[“application/x-shockwave-flash”]) ? navigator.mimeTypes[“application/x-shockwave-flash”].enabledPlugin : 0;
if ( plugin ) {
var words = navigator.plugins[“Shockwave Flash”].description.split(" ");
for (var i = 0; i < words.length; ++i)
{
if (isNaN(parseInt(words*)))
continue;
var MM_PluginVersion = words*;
}
var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf(“MSIE”)>=0
&& (navigator.appVersion.indexOf(“Win”) != -1)) {
document.write(’<SCR’ + 'IPT LANGUAGE=VBScript&gt;
'); //FS hide this from IE4.5 Mac by splitting the tag
document.write('on error resume next
');
document.write(‘MM_FlashCanPlay = ( IsObject(CreateObject(“ShockwaveFlash.ShockwaveFlash.” & MM_contentVersion)))
‘);
document.write(’</SCR’ + 'IPT&gt;
');
}
if ( MM_FlashCanPlay ) {
document.getElementById(“hasflash”).style.backgroundColor=“yellow”;
} else{
document.getElementById(“noflash”).style.backgroundColor=“yellow”;
}
}
//–>
</SCRIPT>

<style>
#hasflash {
font-size:26px;
font-family:Arial, Helvetica, sans-serif;
}
#noflash {
font-size:26px;
font-family:Arial, Helvetica, sans-serif;
}
</style>

</head>

<body onload=“test()”>
<div id=“hasflash”>Has flash</div>
<div id=“noflash”>No flash</div>
</body>
</html>

Cheers, Richter

Anyone? Maybe I shouldve used a sexier title than just ‘flash detection blah blah’ PLEASE anyone who knows anything about changing CSS ID’s / classes from a Javascript if/else statement?

The Error is you have an I.D.10.T error. All signs and evidence appear to point towards the coder…:smiley:

I told you, COM…C++…Applet… not J/Script:hitman:

Your 100% sure your browser just doesn’t have Javascript Disabled?:thumb:

Maybe you got a freeze mouse when doing your coding??:worried:

Tonking :thumb2:

ok world we can obviously ignore that last post…

Now seriously here is a link to what I have: http://www.untitled-project.com/jobtest/css-flash-test2.htm

Please view in Firefox first to see what Im trying to do - it works - view source to see the code (as posted previously).

BUT in IE it falls over. Now the kirupa code (from the bottom of this page http://www.kirupa.com/developer/mx/detection.htm ) seems to fall over when I put it in a function and call it from the <body onload. It returns ‘undefined’ for the variable MM_FlashCanPlay as soon as it is put inside the function and run. I note that javascript is writing out some vbscript here for the benefit of IE but I really have no idea why. I think that the value of MM_FlashCanPlay can not properly be set then, but again I dont know why. View source in IE to see what it is writing out… strange to me.

Please can someone have a look at this… Im new to this forum and if its all out of your leagues just let me know so I can seek out some help somewhere else. I was hoping that since I found the tutorial on Kirupa there might be help here too.

Cheers!(-:
Richter