UPDATE:
On November 8th, 2007, Microsoft announced on their blog that they have licensed the technology from Eolas and will be removing the “Click to activate” behavior in IE.

http://blogs.msdn.com/ie/archive/2007/11/08/…activex-update.aspx

UPDATE:
I’ve posted a follow up to this article in which I recommend alternatives to the method described below.

Microsoft recently rolled out an update for Internet Explorer that changes the way ActiveX controls (including Flash, Java Applets, etc.) can be activated. Long story short, Microsoft lost a lawsuit to Eolas regarding how ActiveX controls automatically become activated when a page loads. Rather than simply buy a license from Eolas, Microsoft decided to throw the web community under the bus and change the way ActiveX controls load so that a user is required to click on an ActiveX control to activate it.

There are JavaScript solutions available. However, most of them require you to replace your existing <applets>, <objects>, or <embed> elements with a script tag that will write out the desired control. In my opinion, the idea of having to go through all existing code and replacing <applets>, <objects>, or <embed> elements with a <script> seems flawed.

  1. That’s a lot of work, particularly for pages with multiple ActiveX objects on them.
  2. Users with JavaScript disabled will not see your ActiveX content.
  3. It requires that you embed “behavior” (the script to write the tag) into your “content” (the HTML of the page).

So I’m going to document what I feel is a better approach. This method uses the window onload event handler, thus keeping your content free of “behavior”, and is much easier to implement as it does not require searching each page for current implementations and replacing them with a script tag. In addition, for those users that have JavaScript disabled, the ActiveX element will still be shown (the same can’t be said for the other solutions without the use of the <noscript> element). The user will still need to “click to activate” the object in that case, but this seems much more accessible to me than not showing the content at all, and less work than adding <noscripts> as well.

Note, I have not tested this in depth. I’ve tried this using a Java Applet and it works as expected. I would be interested to hear feedback from others as to how well this works with Flash and other ActiveX components.

Step 1:
Create a file called activeX.js. Paste the following code into that file:

/*
 * Attach this to the onload event handler
 * to make sure all of the items we're
 * activating are available via the DOM.
 */
function activateActiveX()
{
    var activeXObjTypes = new Array( "applet", "embed", "object" );
    for ( var i = 0; i < activeXObjTypes.length; i++ ) {
        var xObj = document.getElementsByTagName( activeXObjTypes[i] );
        for( var j = 0; j < xObj.length; j++ ) {
            xObj[j].outerHTML = xObj[j].outerHTML;
        }
    }
}

Step 2:
In the <head> of your HTML document that contains <object>, <embed>, or <applet> elements, paste the following code:

<script type=”text/javascript” src=”activeX.js”> </script>
<script type=”text/javascript”>
window.onload = activateActiveX;
</script>

That’s it!

Note, if you have other onload events that need to be called, you can do something like this:

window.onload = function(){
    activateActiveX();
    alert("Hello World");
}