Inline ActiveX object activation workaround.
If you work with ActiveX elements in the browser, you properly already know that these elements now require activation before they can receive keyboard and mouse input. I will in this article shortly describe why Microsoft had to do this change, how Microsoft suggest you solve this issue and finally provide you with my personal solution that allows you to use ActiveX elements inline without requiring activation.
Microsoft did of course not just one day decide to change the way ActiveX objects work because they felt like it. Rather the change is a result of a long running patent dispute with Eolas Technologies and the University of California. Instead of facing a $500 million bill in damages, Microsoft decided to tweak the browser just enough for them not to be liable.
To minimize the impact this change would have on pages that uses ActiveX, Microsoft released a workaround for the activation process. The workaround simply require you to create the ActiveX object using JavaScript located in a an external file.
The community already used Microsoft’s proposed workaround to create easy to use libraries. My favorite is activateActiveX which allows you to work with object and embed tags as you used to by only requires you to insert a script file in the top or bottom of your homepage.
Common for all of these solutions is that they require an external script to work. Personally I don’t think this is to large a hassle, but I could not resist to look into it when people kept asking me if I knew a solution that did not require an external file.
During my research I found several workarounds, where the following was the best in my opinion.
In the above code we use the fact that the javascript: method writes the return value of the executed script to the document. The return value is evaluated in the same manner as the content of any files we open in the browser and therefore we are able to use this to generate html pages, or script segments as we do above. Using this method Internet Explorer is fooled into thinking that we actually did load an external script and we can then use Microsoft’s own solution, or our favorite external script, to complete the task.
Safari does however not support the javascript: method, I added the first line of the script to fix this.
A word of warning!
I do not know the specifics of the patent case but I can imagine that this is a direct violation. If this is the case there is a good chance that Microsoft will change the way javascript: behaves. After all its $500 million, and they had no problem removing about: and the ability to generate XBM images in the past.
on April 26th, 2006 at 6:57 pm
Actually it is great workaround! Will save a lot of time for developers that had to make some external script files even if they didn’t need to have any.
Espescially AD people will love this one :-)).
Nice thinking Chris hehe.
on April 26th, 2006 at 7:12 pm
Very useful article, I’ll almost certainly be using it in the future, I like the Safari Fix too! Very clever work chris!
-Matt
on April 26th, 2006 at 7:15 pm
Super nice solution!
What should we all do without people like you? I’m sure me and many others will be very gratefull!
Go Chris.
on April 27th, 2006 at 9:31 am
Cool
Now what I would really like to see is a solution that lets me use objects normally, and then fixes the IE ‘feature’ with an external script that runs onload. I cant believe how MS thinks its perfectly ok to suddenly make every embedded object completely javascript dependant.
Now, I experimented a bit with trying to make such a solution, and I actually also succeeded, but it seems that the flash plugin doesnt properly load the flash files when the object tags are written after page load. They just become blank.
You can see the experiment here
on April 27th, 2006 at 10:28 am
Munter take a look at the activeActiveX link write about in the article, its exatley what you want :)
on April 27th, 2006 at 1:01 pm
Well, this solution is not new. Actually Microsoft and Macromedia came up with the same solution (back in 2001 I think) when EOLA started the lawsuit against Microsoft.
And luckily for that because I have since 2001 used this solution in about 300 courses which I do not have to re-do now!
/Ole
on April 27th, 2006 at 3:41 pm
Hi Ole
I would really like to see your solution, do you have an example or two somewhere? :)
on April 27th, 2006 at 5:20 pm
I prefer using SWFObject or UFO, as seen on this sample page. External files rock :)
on April 27th, 2006 at 9:59 pm
Looks cool to Krijn. My hack just allows you to implament the UFO solution directley into your page, removing the need for an external script.
Well oki oki in most cases it does not matter, but I knew a few people who would prefere to just have one html file, with all the scripts etc embedded directley into there file.
on June 9th, 2006 at 3:46 pm
function axblast(id) {
/*
Embedded Objects Active X Warning Remover for IE
A little dutch work arround
Use: put your embed html code (flash,movie, etc)
between a div tag with an id in plain html.
trigger the axblast(your_div_id);
*/
if (id == undefined) { return false; }
// Rewrite code for IE browsers only
// Get the object HTML from div
if (document.all && document.all[”+id+”]) { html = document.all[”+id+”].innerHTML; }
// Write the same HTML back - couldnt be easier (-.0)
if (document.all && document.all[”+id+”]) { document.all[”+id+”].innerHTML = html; }
}
on June 9th, 2006 at 4:38 pm
function axblaster(id,html) {
/*
Use this for writing Object Html code to a (div) id
Sample use:
Some search engine index text if you want
code = ”;
code += ”;
code += ”;
code += ”;
axblaster(”flashmovie”,code);
*/
if (id == undefined) { return false; }
if (html == undefined) { var html = “”; }
if (document.layers && document.layers[”+id+”]){
var doc = document.layers[”+id+”].document;
doc.open(); doc.write(html); doc.close();
} else if (document.all && document.all[”+id+”]) {
document.all[”+id+”].innerHTML = html;
} else if (document.getElementById && document.getElementById(”+id+”)) {
document.getElementById(”+id+”).innerHTML = html;
}
}
on July 1st, 2006 at 7:47 am
HI, Its a great idea,
I also do the same thing. Once the site is complete, take all the flash ekements from our site design , put it in extermal javascript file and insert that javascript into website. Works fine but ….
Can Microsoft not pay 500 M and let it be like it was earleir :) They can divert some from Mr. Buffets Donations to pay that :) :)
Cheers
Vipin
on July 18th, 2006 at 5:59 pm
Nice trick. You said that you found it during research. Can you elaborate on that?
Also, I created an external script that fixes existing pages, with the HTML already there. It uses the DOM to rewrite the node, using an external file. Just add a link to the external javascript and you’re set to go. My script needs to be tested more — I wrote it last night. See an example at:
http://dhtmldev.com/examples/js/activate_x/
If you want to provide feedback, please use my javascript forum, http://dhtmldev.com/forums/index.php?board=3.0
on July 20th, 2006 at 9:22 am
Chris,
What can I say.. excellent script man. simple yet very effective. It took me a while to look for a solution that would work in one of the portals that I was making, and this did the trick. Pulling an external file did not work but your script hit the bullseye.
Great job man and more power to you.
on July 20th, 2006 at 5:09 pm
“You said that you found it during research. Can you elaborate on that?”
I have quite alot of experiance with javascript and used a few hours trying to find away around the issues
on August 2nd, 2006 at 2:35 pm
I have xxxx.asp and im using below code. From above solution i can not get clear idea where to use the code mentioned above. So please guide.
Help
on November 8th, 2006 at 10:59 pm
Hehe,
I just found out, IE7 doesn’t allow any more javascript protocol usage in SRC attribute… any suggestions?
Gevorg
on April 3rd, 2007 at 11:52 am
Hello all,
since the solution with the javascript protocol usage in the SRC attribute does not work with my IE6 (probably some of the latest security patches disabled that functionality), I used the MSDN way and created an external JS-file.
It works but I discovered the following problem: After I delete all cached offline content and reload the page, I HAVE to activate the control. If I close the browser and open a new one, the activation is not needed.
Does anyone have an idea what causes this annoying behaviour?
Thanks in advance, Ingmar
on April 30th, 2007 at 3:12 am
I tried to get javascript to work with other embed tags, all said the id was undefined, finally this one, in all simplicity worked great.
Thanks you saved from pulling out my hair
on August 30th, 2007 at 10:52 am
Other simple solution for elimination of a “Click to activate” IE problem
——–
Just add in the head of your page the script:
and at the end of the page:
fixFlashActivation();
the problem is solved!
———-