Friday, July 28, 2006

IE7 Supports XMLHttpRequest Natively, My Ass

IE7 Beta 3, installed fresh. Before you ask: yeah, I made sure I had the checkbox checked for "Enable native XMLHTTP Support." So I go to check some of my code and get the following:

A Runtime Error has occurred.
Do you wish to Debug?

Line: 286
Error: 'XMLHttpRequest.prototype' is null or not an object.
Which means a detect script that used to weed out IE6's non-XMLHttpRequest support like this just fucking breaks in IE7:
if (window.XMLHttpRequest &&
XMLHttpRequest.prototype.isPrototypeOf(someobject)) {
} else {
So, basically, this makes me think that they didn't port shit to a native JavaScript object. This just looks like they made an ActiveX control that runs even if you disable ActiveX.

Labels: ,

Wednesday, July 19, 2006

IE cannot set events via the DOM in order to pass parameters to functions/methods

Not one of the following examples will work in IE:

anchor.setAttribute('onclick', 'doThis(' + param + ');');
anchor.onclick = 'doThis(' + param + ');';
anchor.onclick = new Function('doThis(' + param + ');');
anchor.onclick = function() { doThis(param); };
anchor['onclick'] = 'doThis(' + param + ');';
anchor['onclick'] = new Function('doThis(' + param + ');');
anchor['onclick'] = function() { doThis(param); };

If I want to dynamically write out a list of links, I have to fucking spell out the entire string rather than using DOM methods and then innerHTML my way to working code, or stick javascript:void(...); into the href. I can't define event handlers without some serious hacked-out solution, because I need to pass a parameter when it gets called.

Edited 3/5 to add: rather than post yet another comment in reply to yet another anonymous comment...any of the above will work in IE, provided you call anchor.parentNode.innerHTML = anchor.parentNode.innerHTML afterward. Yes, you must tell IE explicitly to listen to the markup contained in the page that it already knows about.

Labels: ,

Monday, July 17, 2006

When PRE does not mean PRE

So say you have a <pre> element. Say you need to update that <pre> with new contents. This should work, right?

document.getElementById('my_special_pre').innerHTML = some_big_block;

Well, almost. True, it does replace the contents of my_special_pre with some_big_block. However...IE for some reason simply forgets to preformat the white-space. Even if you assign the new content and then explicitly tell it you really do want that block to white-space: pre; - it still can't figure out that it needs to actually listen to newlines.

Now, I would at this point guess that IE parses the XML, basically ignoring the white-space, making some_big_block a single line of text without newlines. Except this corrects the behavior:

document.getElementById('my_special_pre').innerHTML = some_big_block.replace(/\n/g, "<br />\n");

Fucking brilliant. That hurt to write, so somebody please let me you know of a better way to correct this moronic IE "quirk."

*edited for a small grammer fix.

Labels: ,