Ever get that annoying “Click to activate and use this control” message in IE when you embed a Flash movie? I did and couldn’t find a solution that worked as well as I’d like. A quick browse of my Google results brought be here, but the solution there was kinda sloppy in my opinion. But with a few tweaks, I got things working…and with the added street cred’ of not introducing a single global variable.
Here’s the code:
(function()
{
var clear = function(a)
{
for(var i=0; i < a.length; i++)
{
a[i].outerHTML=a[i].outerHTML;
}
};
clear(document.getElementsByTagName("object"));
clear(document.getElementsByTagName("embed"));
})();
The original code I found only applied the fix to object tags. But since use of the object tag is becoming deprecated, we also need to touch the embed tags as well. The code above does both and is wrapped in an anonymous function to keep all is private bits private.
Finally, since this is an IE-only fix, we should make use of IE’s conditional comments so other browsers don’t have to be bothered by the script. Assuming we placed (a minified version of) the code into a file named controlFix.js, we then add the following code at the end of the source code:
<!--[if IE]> <script type="text/javascript" src="controlFix.js"></script> <![endif]-->
If you’d like to use this on your site, you can download the minified JavaScript here.


