Object Patent Magic

Update: Microsoft patched all versions of IE last April (2008), so this is really obsolete at this point. I’m going to ignore click to activate in general for myself. I see no need to concern myself with it any further. I’m also going to take this out of future HistoryKeeper releases.

When Microsoft released a patch that created the “click to activate” annoyance on most things embedded via the object tag, the race was on to come up with a solution. I wanted to see how small a solution I could come up with, and see if I could make it a drop in solution. With the help of some friends on the flashcoders mailing list, and aside from a couple of caveats, we have a solution – I call it Object Patent Magic.

So if you are in a place where you want to use an object tag to embed your swf, but you’d rather not have your visitors “click to activate” your swf movie (might even work with other active x controls, like Windows Media Player for example – not tested) – you have found the right tool.

To use this, download the javascript file, and then embed it in the head section of your html code thusly:

<style type="text/css" id="ObjectPatentMagic">object{display:none}</style>
<script type="text/javascript" src="ObjectPatentMagic-p.js"></script>

Wrap it in conditional comments like this:

<!--[if IE gte 6]>
<style type="text/css" id="ObjectPatentMagic">object{display:none}</style>
<script type="text/javascript" src="ObjectPatentMagic-p.js"></script>
<![endif]-->

Now only IE 6+ will apply the patch. That’s it! You’re all done! No configuration necessary.

You can view an XHTML 1.1 example here (link is no longer active).

Caveat #1: The above linked examples are actually not even working (I’ll update with some that do soon). It seems some swf files don’t load properly with Object Patent Magic, if the swf is not already in the user’s cache, so make sure to test, test, test with an empty cache, just to be sure. This problem is not unique to Patent Magic, but thankfully, doesn’t seem very common.

Caveat #2: As a byproduct of the tricks this script uses to make the click to activate thing go away, the swf will not start running until it has completely downloaded. This means if you have a large swf, the user might be looking at an empty screen, no load bar, while the swf is downloading. I have an experimental solution to that in the works, but it’s not finished yet, so be aware, that either a large swf, or a lot of swf on the page, will keep the user in the dark until all swfs are finished downloading.

How does it work?

Object Patent Magic does two things. First, it hides all objects in the page using css. Then when the page’s onload event fires, it replaces all the objects on the page, with themselves, using the externally linked js file. Then disables the css that hid them in the beginning. No more “click to activate” appears from then on.

This relies on the fact that hidden swf objects do not begin to play, until they are shown, but they do download, and the page’s onload event waits for them. I did do a bit of testing to make sure the swf files are indeed, not running, and to make sure they are not redownloaded (it does reload the swf, but from the cache – http explorer says so). These assumptions, could use a bit more testing though, especially with older version of Flash, as I’m not sure if this is an IE active x feature, or Flash Player feature that I’m exploiting here.

If you find it useful, please, enjoy!

Special thanks to Elibol and Karina Steffens of ObjectSwap.

Note: This doesn’t solve the click to activate issues in Opera 9+ yet.

2 thoughts on “Object Patent Magic”

  1. You cannot believe how long ive been googling for something like this. Browsed through 10 pages of Google results couldnt find diddly squat. Very first page on Bing. There this is…. Really gotta start using that more often

  2. I’m not entirely sure this ever really worked (which is why I don’t have any links to it in the main nav bar). Also, the problem it was meant to solve has been fixed by Microsoft with a patch delivered through Windows Update a long time ago (the other reason there’s no link).

    If you do need this for some reason, I really suggest testing this very thoroughly (especially if the content is already cached – I’m pretty sure I remember that being a significant bug with this).

Leave a Reply

Your email address will not be published. Required fields are marked *