Hi elibol,

Great job! And it seems that great minds think alike - yours is a similar
solution to the one I've been working on myself... I posted an earlier
version of my script on this list on Monday under the subject "Active X and
Microsoft IE", but it got no comments. 
I've done some more work on it since, and I'm including the new script for
comparison.

I also added a nifty flash detection - if you add a param with the name
"flashVersion", the script will check if the installed flash version matches
the param's value (same or higher) and react accordingly.
The flash detection bit works with all browsers, the flash replacement bit
only with IE.

Karina

----------------------------------------------------------------------------
--------------------------
//Set to true if you want it to apply only to flash objects and/or objects
with the class "objectH"
//Otherwise this will apply to all objects. default: false.
var flashOnly = false;

//Check if the browser is InternetExplorer
var ie = (navigator.appName.indexOf("Microsoft") != -1)

//Add a stylesheet for the hidden/visible classes, to prevent a jump after
the object is replaced.
if (ie){
        document.write ("<style> object{visibility:hidden;} </style>")
}

/*Replace all flash objects on the page with the same flash object, 
by rewriting the outerHTML values
This bypasses the new IE ActiveX object activation issue*/
replaceFlash = function(){
        //Get a list of all ActiveX objects
        var objects = document.getElementsByTagName('object');
        
        for (var i=0; i<objects.length; i++){
                var o = objects[i];
                
                //The outer html omits the param tags, so we must retrieve
and insert these separately
                var paramList = o.getElementsByTagName('param');
                var params = "";
                for (var j = 0; j<=paramList.length; j++) {
                        if (paramList[j] != null){
                                //Check for version first - applies to all
browsers
                                //For this to work, a new param needs to be
included in the object with the name "flashVersion" eg:
                                //<param name="flashVersion" value="7" />
                                if (paramList[j].name == "flashVersion"){
                                        var hasFlash =
detectFlash(paramList[j].value)
                                        if (!hasFlash){
                                                stripFlash(o, paramList);
                                                break;
                                        }
                                }
                                params += paramList[j].outerHTML;
                       
                        }
                }
                //Only target internet explorer
                if (!ie){
                        continue;
                }
                
                //If flashOnly var is true then only flash objects and those
marked with objectH will be replaced.
                if (flashOnly &&
o.outerHTML.indexOf("application/x-shockwave-flash") == -1 &&
o.className.indexOf ("replaceFlash") == -1){
                        continue;
                }               
                
                //Get the tag and attributes part of the outer html of the
object
                var tag = o.outerHTML.split(">")[0] + ">";      
                
                //Add up the various bits that comprise the object:
                //The tag with the attributes, the params and it's inner
html
                var newObject = tag + params + o.innerHTML + " </OBJECT>";
                
                //And rewrite the outer html of the tag 
                o.outerHTML = newObject;
        }
        //Make the object visible again
        if (ie){
                document.write ("<style> object{visibility:visible;}
</style>")
        }
}

detectFlash = function(version){
        if(navigator.plugins.length){
                //Non-IE flash detection.
                var plugin = navigator.plugins["Shockwave Flash"];
                if (plugin == undefined){
                        return false;
                }
                var ver = navigator.plugins["Shockwave
Flash"].description.split(" ")[2];
                return (Number(ver) >= Number(version))
        } else {
        //IE flash detection.
                try{
                        var flash = new
ActiveXObject("ShockwaveFlash.ShockwaveFlash." + version);
                        return true;
                }
                catch(e){
                        return false;
                }
        }
}

//Replace the object by a div tag containing the same innerHTML.
//To display a message for the user and a link to the flash installation
page, place it inside the object tag.
stripFlash = function (o, paramList){
        var newHTML = o.innerHTML
        newHTML = newHTML.replace ("embed", "span")     
        var d = document.createElement("div")
        d.innerHTML = newHTML
        d.className = o.className
        d.id = o.id
        o.parentNode.replaceChild(d, o)
}



//USAGE: There are three possible ways to inititalise the function:
//1. If this is the only script that uses window.onload, uncomment the
following lines:
//window.onload = replaceFlash;

//2. Use a general init() function in a central location accessible by all
the scripts. For example:
/*
init = function(){
        replaceFlash();
    othercode();        
}
window.onload = init;
*/

//3. Place a call to this function towards the end of the html document 
//(or a reference to an external script with this function), eg:
/*<script language="JavaScript"
type="text/javascript">replaceFlash()</script>*/
/*<script type="text/javascript" src="scripts/initReplace.js"></script> */

----------------------------------------------------------------------------
----------------------------





> -----Original Message-----
> From: elibol [mailto:[EMAIL PROTECTED] 
> Sent: 20 April 2006 22:29
> To: Flashcoders mailing list
> Subject: Re: [Flashcoders] New wrinkle in IE activation issue...
> 
> I've modified it to transfer FlashVars
> 
> http://anticipatechange.com/huseyin/patentMagic/
> 
> 
> On 4/20/06, Kevin Newman <[EMAIL PROTECTED]> wrote:
> >
> > All I'm doing to try and keep the objects from loading is 
> defining all 
> > objects with display:none - is there a more reliable way to prevent 
> > objects from loading in the background? I took a quick look on msdn 
> > for some ActiveX magic method, but wasn't able to find anything.
> >
> > It looks like it does loose the values of some of the params 
> > unfortunately. If there is a way around that, I'd be happy to 
> > implement it.
> >
> > Kevin N.
> >
> >
> > elibol wrote:
> > > It doesn't seem to Geoff, I tested it with a 100%x100% object:
> > >
> > > http://anticipatechange.com/huseyin/shifty.html
> > >
> > > The object tag has noscale params, there is one problem 
> though, it 
> > > seems
> > as
> > > if the replaced objects appear to still be loading from 
> the browsers 
> > > perspective.
> > >
> > > Besides this, seems like a reliable exploit so far. Nice 
> job Kevin.
> > >
> > > M.
> > >
> > > On 4/20/06, elibol < [EMAIL PROTECTED]> wrote:
> > >
> > >> Would it make sense for this to work with all Active X 
> Objects? The
> > idea
> > >> is to override object activation by rewriting the 
> objects after the
> > document
> > >> is loaded? Is this a hole in the activation process, 
> where it will 
> > >> only force activation when the page is being 
> initialized? Objects 
> > >> written
> > after
> > >> the page is loaded slip through?
> > >>
> > >> M.
> > >>
> > >> On 4/20/06, Kevin Newman < [EMAIL PROTECTED]> wrote:
> > >>
> > >>
> > >>> I didn't want to have to redefine all the stuff that 
> has already 
> > >>> been defined in the html object. So I made this: :-)
> > >>>
> > >>> http://www.unfocus.com/projects/PatentMagic/
> > >>>
> > >>> A super tiny js file include and a stylesheet takes care of all 
> > >>> object activation. It's a bit brute force, but it 
> should get the 
> > >>> job done if you are looking for a quick fix and are 
> using static 
> > >>> embedded html. If anyone has any ideas on how to make this more 
> > >>> robust, please let me know. :-)
> > >>>
> > >>>
> > >>> Kevin N.
> > >>>
> > >>>
> > >>> Geoff Stearns wrote:
> > >>>
> > >>>> you could do this with flashobject really easily.
> > >>>>
> > >>>> just call fo.write() whenever you want and it will replace the 
> > >>>> object you target with your flash movie.
> > >>>>
> > >>>>
> > >>>>
> > >>>> On Apr 20, 2006, at 11:04 AM, Kevin Newman wrote:
> > >>>>
> > >>>>
> > >>>>> I prefer solutions that try to hide IE's lack of conformity, 
> > >>>>> like Dean Edwards's IE 7 script:
> > >>>>> http://dean.edwards.name/IE7/
> > >>>>>
> > >>>>> There are just too many installations to 
> realistically ignore them.
> > >>>>>
> > >>>>> Speaking of hacking on IE, is there a way to prevent 
> an object 
> > >>>>> from loading? By that I mean, I want to use Object 
> tags to embed 
> > >>>>> a Swf, but I don't want it to download or load in the 
> background 
> > >>>>> until I tell it to via a script interaction (vbscript or 
> > >>>>> javascript). Will hiding it via css do the trick, or 
> will I need 
> > >>>>> to take further steps to keep it from loading?
> > >>>>>
> > >>>>> Thanks,
> > >>>>>
> > >>>>> Kevin N.
> > >>>>>
> > >>>>>
> >
> >
> > _______________________________________________
> > Flashcoders@chattyfig.figleaf.com
> > To change your subscription options or search the archive:
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> > Brought to you by Fig Leaf Software
> > Premier Authorized Adobe Consulting and Training 
> > http://www.figleaf.com http://training.figleaf.com
> >
> _______________________________________________
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training 
> http://www.figleaf.com http://training.figleaf.com
> 
> 

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to