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.
- That’s a lot of work, particularly for pages with multiple ActiveX objects on them.
- Users with JavaScript disabled will not see your ActiveX content.
- 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");
}
6 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Relative to putting the focus on the activex control, all works well with postback. However, when I use Ajax to reload the control without postback, the control loses focus even if I call the activateActiveX function. Have you seen any fixes for this? Thanks.
Steve
Steve, could you post an example that demonstrates what you mean?
Take a look at this solution with just 2 lines of code.
this site which has a solution to flash objects ‘click here to activate control’ not seen it before anywhere and it works on blogs as well. http://clickheretoactivate.blogspot.com/
Here is the top part of my webpage:
NETPAW
window.onload = activateActiveX;
Version 1.2.8
I also copied and pasted the other code into a file called activeX.js and placed that file in the same directory as the code above. It still does not work for me (requires click to activate control). Can you tell me what I am doing wrong?
Thanks,
Bob.
@Bob
First, let me say that I no longer recommend this method. Better alternatives have been released since I originally posted this. Check my follow up post:
http://www.fotiweb.com/?p=19
I would strongly recommend using one of those methods instead.
As for your example, it’s hard to tell what you might be doing wrong without seeing a full code example. Do you have a that is overriding the window.onload? Or do you perhaps have another window.onload method that is overriding it? You could try throwing some alert statements into the JavaScript to see what it’s doing.
But like I said, check out one of the other methods in my follow up post. They are much better and well tested.
Continuing the Discussion