IE ActiveX Change
"Click to activate and use this control"

Friday, April 21, 2006

Rewrite div solution

This solution is very similar to the <noscript> solution published earlier, but my original version using <divs> didn't work if you used FlashVars parameters. However, thanks to a suggestion in the Flash Forums from hemels I've updated to JavaScript to workaround the problem.

First of all create a JavaScript file called, say, ieupdate.js, containing the following code:

var bo_ns_id = 0;

function startIeFix(){
if(isIE()){
document.write('<div style="display: none;" id="bo_ns_id_' + bo_ns_id + '">');
}
}

function endIeFix(){
if(isIE()){
document.write('</div>');
var theObject = document.getElementById("bo_ns_id_" + bo_ns_id++);
if(theObject.firstChild.data){
theObject.firstChild.removeAttribute('data');
}
var theParams = theObject.getElementsByTagName("param");
var theParamsLength = theParams.length;
for (var j = 0; j < theParamsLength; j++) {
if(theParams[j].name.toLowerCase() == 'flashvars'){
var theFlashVars = theParams[j].value;
}
}
var theInnnerHTML = theObject.innerHTML;
var re = /<param name="FlashVars" value="">/ig;
theInnnerHTML = theInnnerHTML.replace(re, "<param name='FlashVars' value='" + theFlashVars + "'>");
theObject.outerHTML = theInnnerHTML;
}
}

function isIE(){
var strBrwsr = navigator.userAgent.toLowerCase();
if(strBrwsr.indexOf("msie") > -1 && strBrwsr.indexOf("mac") < 0){
return true;
}else{
return false;
}
}

This will then need to be included within the <head> tags for each page:
<script type="text/javascript" src="ieupdate.js"></script>


Then you need to include a line directly before, and directy after each <object> tag:

<script type="text/javascript">startIeFix();</script>
<object ...
etc etc
</object>
<script type="text/javascript">endIeFix();</script>

And that is it! The code checks for IE on a PC, and so doesn't affect any other browsers, the <object> is enclosed in a div with its display style set to 'none', and so doesn't run until the external javscript writes it back out (therefore doesn't cause any double running issues), and the code still maintains any FlashVars too!

0 Comments:

Post a Comment

<< Home