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

Thursday, April 20, 2006

<noscript> solution

In the Macromedia Forums, fpproductions came up with a clever workaround using the <noscript> tags. The solution works by getting IE to add a <noscript> just before the object, and a </noscript> just after the object, and we can then use JavaScript to read the contents of the <noscript> tag, and write it back out again. I changed fpproductions original script for that the object tag is written out as soon as IE processes each object tag.

Firstly create a JavaScript file called, say, ienoscript.js containing:


var bo_ns_id = 0;

function startIeFix(){
if(isIE()){
document.write('<noscript id="bo_ns_id_' + bo_ns_id + '">');
}
}

function endIeFix(){
if(isIE()){
var theObject = document.getElementById("bo_ns_id_" + bo_ns_id++);
var theNoScript = theObject.innerHTML;
document.write(theNoScript);
}
}

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

This file is referenced inbetween the <head> and </head> tags:

<script type="text/javascript" src="ienoscript.js"></script>

Then, for each <object> tag you need to add a line above and below each one.


<script type="text/javascript">startIeFix();</script>
<object
etc etc
</object>
<!--[if gte IE 6]></noscript><![endif]--><script
type="text/javascript">endIeFix();</script>

It seems to work OK on all the browsers I tried it on, the only exception being Opera when it identifies itself as IE, which I guess could be solved using the [if gte IE 6] to write the top <script> bit out too. Something like:

<!--[if gte IE 6]><script type="text/javascript">startIeFix();</script><![endif]-->
<object
etc etc
</object>
<!--[if gte IE 6]></noscript><script
type="text/javascript">endIeFix();</script><![endif]-->


Note:
This technique also preserves any FlashVars parameters too.

0 Comments:

Post a Comment

<< Home