Thursday, March 8th, 2007

Another way to get around ActiveX silliness

Category: JavaScript, Tip

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

Posted by Dion Almaer at 6:52 am
16 Comments

+++--
3.3 rating from 29 votes

16 Comments »

Comments feed TrackBack URI

jQuery(‘object’).each(function() {this.outerHTML = this.outerHTML; });

Comment by Webunity.nl — March 8, 2007

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.

Comment by jd — March 8, 2007

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.

Comment by Mark Wubben — March 8, 2007

$$(‘object’).each(function(o){ o.outerHTML = o.outerHTML; });

Comment by jd — March 8, 2007

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.

Comment by Eric Anderson — March 8, 2007

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.

Comment by Tommy Valand — March 8, 2007

So… people posting shorter code snippets… Why don’t you also post the 60 kb+ code behind that?

;)

Comment by José Jeria — March 8, 2007

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.

Comment by Trevor — March 8, 2007

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)

Comment by jd — March 8, 2007

Doesn’t seem to work on Vista/IE7

Comment by Steven — March 8, 2007

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?

Comment by Kiran — March 9, 2007

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)

Comment by jd — March 9, 2007

Doesn’t seem to work at all!
I tried it on IE7 and IE6 running on Windows XP and it doesn’t work.

Comment by Alexandre Figueiredo — March 9, 2007

It works only in IE6, but doesn’t work in IE7 on my computer.

Comment by GolDen — March 12, 2007

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);

Comment by Eric Anderson — September 10, 2007

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?

Comment by Jamie O — November 15, 2007

Leave a comment

You must be logged in to post a comment.