Thursday, March 8th, 2007
Another way to get around ActiveX silliness
Eric Anderson has written his own script to get rid of the annoying "Click here to activate" IE now puts on all ActiveX controls (including Flash).
There are other solutions such as UFO and SWFObject that we have discussed in the past.
-
-
if (navigator.appName == "Microsoft Internet Explorer") (function() {
-
var onload = window.onload || function(){};
-
document.body.setAttribute('onload', null);
-
window.onload = function() {
-
onload.apply(this, arguments);
-
var tags = ['object', 'embed', 'applet'];
-
for( i=0; i<tags.length; i++ ) {
-
var elements = document.getElementsByTagName(tags[i]);
-
for(j=0; j<elements.length; j++)
-
elements[j].outerHTML = elements[j].outerHTML
-
}
-
}
-
})();
-












jQuery(’object’).each(function() {this.outerHTML = this.outerHTML; });
I posted this link the last time the subject was brought up.
http://www.mix-fx.com/flash-prompt.htm
Its framework independent. Like 3 lines of code.
Interesting (and unubtrusive!, aside from the onload handler) solution!
There is a bug in IE when changing the innerHTML of an OBJECT element’s parent will make IE forget about the Flash variables passed to that OBJECT. I wonder if that’s also the case when using outerHTML. One other issue I can think of is redoing the work of libraries like SWFObject and also sIFR which will have put the OBJECTs in place before window.onload. This of course is also the responsibility of the person using the script.
$$(’object’).each(function(o){ o.outerHTML = o.outerHTML; });
There are much shorter ways to do this if you have prototype or something installed as others pointed out. I was mostly wanting something that had no dependencies so it could be placed on any site. I also wanted to preserve any existing onload handler so the script would effectively be invisible (other than making things work). Everything is scoped inside an anonymous function so the global namespace is not even affected.
This method breaks the ActiveX RichText-editor used by Lotus Notes on the web (IEs DHTML Editor).
Whatever is typed in the WYSIWYG-area isn’t filled into the field that is sent back to the server.
I think the problem is that “refreshing” the outerHTML clears the event-listeners on the editor-object.
So… people posting shorter code snippets… Why don’t you also post the 60 kb+ code behind that?
;)
Because those of us who use those libraries don’t just use them for this single purpose?
You know, whenever anyone posts anything Firefox-specific, they should post the several megabytes of code that makes Firefox work.
Good point Jose. For reaching the most devs and for being the most practical, framework independent is the way to go.
However, if you are interested there is a compressed version of Prototype at Prototype’s google group’s page.
http://groups.google.com/group/prototype-core/browse_thread/thread/2a611d702c4deadb
Version 1.5 (offical release) comes in at 14.4kb gzipped (21.8kb with no gzip)
Doesn’t seem to work on Vista/IE7
bytedom.get(’object’).forEach(function(o){o.outerHTML = o.outerHTML});
2.54Kb Memtronic version, 3.86 Packer
This question may sound dumb, but here goes…
How do I use this script in IE?
How do I ensure that this script gets executed everytime I visit a site on the net?
What you want is Trixie (Greasemonkey for IE) :
http://www.bhelpuri.net/Trixie/
It allows you to execute js on every page if you wish. Make a script copy n paste the code from this article and away you go.
8)
Doesn’t seem to work at all!
I tried it on IE7 and IE6 running on Windows XP and it doesn’t work.
It works only in IE6, but doesn’t work in IE7 on my computer.
Looks like it doesn’t work in IE7 because document.body doesn’t exist yet. Try changing
document.body.setAttribute('onload', null);
to
if(document.body)
document.body.setAttribute('onload', null);
I’m having issues with all of the potential solutions described here as well as a smaller equivelent (http://www.mix-fx.com/flash-prompt.htm).
It creates two copies of the object on the page, the first one has no content, the second one does, both seem to have the “click to continue” still. Any ideas?