AJAX in IE without ActiveX
by kae verens on Aug.12, 2005, under ajax, javascript
What a day! Recently, one of our customers was saying that his site wasn’t working whenever he viewed it in his local net-cafe. This was incredible, to me, as every computer I’ve checked it on has displayed fine.
I finally had an inkling of an idea why this was happening, when I asked him to “click help->about in the browser”, to find out what exact version this was happening in. He said that the browser wasn’t allowing him to access that information.
I understood immediately that it was a security thing. Net-cafes would naturally hate to be infected with the myriad viruses out there, so they tend to belt-up their browsers tighter than the average user.
So, I tried to replicate what might be going on – I set my own Internet Explorer to stun – High security setting. When I tried the site, I was not surprised to find that it was not working. The fact that it relies on JavaScript made that a certainty anyway.
To make it work, I needed to turn on “Active Scripting” (what IE calls ECMAScript), and let it run safe ActiveX modules.
Naturally, I’m slightly ashamed that the site doesn’t work properly in a non-javascript environment, but the site is aimed at the overwhelmingly vast majority of people who are normal. The ActiveX thing, though, was a problem.
I began searching through the source of every AJAX library I could think of – Sarissa, JSPan, Sajax, ie7-xml-extras – every single one of them relied on ActiveX.
Surely there must be some XMLHttpRequest library out there that doesn’t rely on ActiveX?
I sat down, and started work on one. It’s Friday, and I’m exhausted after a very long day’s research, so I won’t go too in-depth into it…
There are some problems with the above, which I’ll detail.
First off, the file is a drop-in emulation of the XMLHttpRequest object. I wanted to use the exact same API as every other library on the planet is using.
The short explanation of how it works: the library creates an <iframe>, populates it with the requested data, then returns the source of that object.
That’s not quite as simple as it sounds. I got 90% of the code working in 10% of my working time today, and spent the next 90% of the day trying, and failing, to solve the other 10%.
As it is, the file works – it should be bloody simple to add it to any library out there. The major problem, though, is white-space.
The innerHTML returned by IE is not exactly what it was given, but there is no other way of obtaining it.
Trust me – I spent hours crawling through the MSDN library today (in Firefox, because I had IE set on stun, so the navigation (which is ActiveX-based) wouldn’t work) – there is no other way.
I even tried dynamically creating a text/plain <object> to grab the data from it, but got alerts complaining that this was an ActiveX object!
If anyone out there in blogland has an inkling of an idea how to go forward from here, please do pipe up.
58 Comments for this entry
11 Trackbacks / Pingbacks for this entry
-
Holy Shmoly! :: AJAX in IE without ActiveX
August 13th, 2005 on 10:32 am[...] Kae discovered that AJAX functions in IE depend on ActiveX being enabled. This is terrible – something that’s useful (AJAX) depends on something awful(ActiveX)! Anyway, Kae found a way around this limitation. It’s not complete but it’s a stab in the right direction. Related Stories (ajax, without, activex) [...]
-
» Sajax, without ActiveX « klog
August 14th, 2005 on 8:11 pm[...] On Friday, I announced a non-ActiveX version of XMLHttpRequest, with the proviso that it would require server-side magic. [...]
-
-
» Blog Archive » Ajax en IE sin ActiveX
August 18th, 2005 on 11:15 pm[...] Aunque la verdad… a nivel personal me interesa bien poco si alguien con Internet Explorer y con ActiveX desactivado no puede ver mi pagina si empleo ajax, en mi trabajo les interesa hacer aplicaciones Accesibles, este tio se ha currado un "fork"/ version de sajax en la cual se puede utilizar XMLHttpRequest en IE sin tener ActiveX. http://verens.com/archives/2005/08/12/ajax-in-ie-without-activex/ A quien pueda interesarle [...]
-
Software Development Blog » AJAX Module
August 26th, 2005 on 9:27 pm[...] These were only small things, but then I started trying to learn Javascript OOP. So I converted it to OOP and added support for multiple calls at the same time, the only library available that can do that (as far as I know). I was pretty proud of that fact, so I wondered how to make it even better. Then the idea of making it work on older browsers came in to mind, so I started searching around about using iframes and found Verens’ script which he had made to easily intergrate with AJAX libraries. I was originally planning on peforming all the iframe actions seperately, but his idea was to replicate the XMLHttp object, which makes a more sense and involves less code. So I started coding and spent a couple of days trying to get it all to work in all browsers. [...]
-
A Venture Forth » Blog Archive » What’s Wrong With Ajax?
September 22nd, 2005 on 2:37 am[...] Second, Ajax requires JavaScript and, for Microsoft’s Internet Explorer, ActiveX must be enabled (though there is a workaround). I think this is a manageable issue as most browsers are sufficiently up to date–though some companies and individuals have disabled JavaScript or ActiveX by default for security or privacy related reasons (see here and here). The key is to design applications to degrade gracefully (which is a fancy way of saying that web pages should work for new and old browsers, even if the old browsers don’t support certain new capabilities). Interestingly, Google fails in this regard. Try running Google Maps with JavaScript disabled. It won’t work (they could have produced a Flash-version like this one here–in some ways, it’s better than the original). [...]
-
Get Off Microsoft » Blog Archive » Ajax to Scrub Desktop Applications
October 4th, 2005 on 12:26 am[...] You can, however, get around the ActiveX requirement in IE by using this workaround, or use alternatives to Microsoft’s browser and platform. [...]
-
wendelmaques / Ajax sem ActiveX
May 17th, 2006 on 3:45 am[...] Então, caso nenhum dos dois objetos seja encontrado, e você estaja no Windows com Internet Explorer, você estará num senário hostil com severas restrições de segurança, então é hora de tentar trabalhar sem ActiveX, nesse caso leia o seguinte artigo: “ajax-in-ie-without-activex” e então cheque o script: nonActiveX-XMLHTTPRequest e veja a possibilidade de uso na sua aplicação. [...]
-
links for 2007-04-20 « Skywalker
April 20th, 2007 on 3:20 am[...] klog » Blog Archive » AJAX in IE without ActiveX (tags: Ajax) [...]
-
AJAX in IE without ActiveX | Inspired? No
January 1st, 2009 on 6:19 pm[...] reports: When IE is set to disallow safe Active-X, AJAX applications will not work. So, I tried to replicate what might be going on – I set my own Internet Explorer to stun – High [...]
-
AJAX - kiedy nie jest wspierany i jak si? zabezpieczy? przed tym | Ikeris Sp. z o.o.
January 16th, 2010 on 2:19 pm[...] Internet Explorer 6 ma k?opoty z Ajaksem, kiedy nie ma w??czonej technologii ActiveX, cho? mo?na temu zaradzi?. [...]
August 10th, 2006 on 1:30 pm
As iframes have been deprecated, it’s advisable not to use them.
As fas as Active-X being disabled, it’s already been mentioned that IE7 uses the native request method.
This still won’t work if users have javascript disabled or if they are using a mobile browser / accessability related browser.
WIth AJAX, it really is as simple as using the normal method and having a completely non-javascript method of doing things if it’s disabled.
August 30th, 2006 on 3:39 pm
Hi guys,
Could someone give me a example, how to use it ?
October 26th, 2006 on 7:13 pm
The link to the JS file is broken.
November 2nd, 2006 on 10:30 am
Use CPAINT API available at sourceforge.net .. it has php as well as asp code to help you at the server adn client side and works in all browsers.
Regards,
Arup
February 25th, 2007 on 7:26 pm
The same problem, I’ve encountered: submitting a form into a dynamically created IFRAME: FireFox and Opera worked perfect but IE not!
After 1 day of debugging, I founded that , following solution works:
[CODE]
var iFrameID = ‘ID1′;
var myIFrame = document.createElement(‘iframe’);
myIFrame.setAttribute(‘src’, ‘about:blank’);
myIFrame.setAttribute(‘id’, iFrameID);
myIFrame.setAttribute(‘NAME’, iFrameID);
myIFrame.style.display = ‘none’;
document.body.appendChild(myIFrame);
if((onReadyFunction) && (typeof(onReadyFunction) == ‘function’)) captureEvent(‘load’, function(){ var iFrame = document.getElementById(iFrameID); var doc = (iFrame.contentDocument)?(iFrame.contentDocument):((iFrame.contentWindow)?(iFrame.contentWindow.document):(self.frames[iFrameID].document)); if (doc.location.href == ‘about:blank’) { return; } else { onReadyFunction(doc.body.innerHTML); } }, myIFrame);
if(self.frames[iFrameID].name != iFrameID) { /* *** IMPORTANT: This is a BUG FIX for Internet Explorer *** */ self.frames[iFrameID].name = iFrameID; }
[/CODE]
Meanning that AFTER the iframe is created, it should be checked that self.frames[iFrameID].name is equal with iFrameID
No DIV, nothing else more! That’s all!
The problem was encountered and resolved by me during myAJAX [http://myajax.sf.net] development
July 27th, 2008 on 8:42 pm
Right… Bit insane. I’d rather ActiveX than iframes. Both by js.. so Meh.
July 28th, 2008 on 6:45 am
tobylane, you have missed the point. The reason for this approach is not to avoid ActiveX – it’s because in some IE6 environments, ActiveX is simply not available. so you might prefer to use ActiveX, but that won’t make it work…
October 20th, 2008 on 5:47 am
hi. i am getting this error when i incorporate nonActiveX-XMLHTTPRequest.js to my page..
it says “req is null or not an object”
please help