# Javascript Flash Detection + CSS

**URL:** <https://forum.kirupa.com/t/javascript-flash-detection-css/183830>\
**Category:** web dev\
**Created:** [March 30, 2006, 2:48pm UTC](https://forum.kirupa.com/t/javascript-flash-detection-css/183830 "2006-03-30T14:48:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![richter](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@richter](https://forum.kirupa.com/u/richter)\
**Post date:** [March 30, 2006, 2:48pm UTC](https://forum.kirupa.com/t/javascript-flash-detection-css/183830/1 "2006-03-30T14:48:31Z")

</div>

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](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](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](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)”\>  
\<html xmlns=“[http://www.w3.org/1999/xhtml](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

---

<div class="post-metadata">

**Author:** ![richter](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@richter](https://forum.kirupa.com/u/richter)\
**Post date:** [March 31, 2006, 1:27am UTC](https://forum.kirupa.com/t/javascript-flash-detection-css/183830/2 "2006-03-31T01:27:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TonkingDinosaur](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@TonkingDinosaur](https://forum.kirupa.com/u/TonkingDinosaur)\
**Post date:** [March 31, 2006, 10:25am UTC](https://forum.kirupa.com/t/javascript-flash-detection-css/183830/3 "2006-03-31T10:25:45Z")

</div>

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

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??😟

Tonking :thumb2:

---

<div class="post-metadata">

**Author:** ![richter](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@richter](https://forum.kirupa.com/u/richter)\
**Post date:** [March 31, 2006, 12:00pm UTC](https://forum.kirupa.com/t/javascript-flash-detection-css/183830/4 "2006-03-31T12:00:28Z")

</div>

## 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](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](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
