Bill's Computer Circus
Don't get caught with your system down.
NOTICE: This web site may not render correctly in older browers like Internet Explorer 5.2 for the Mac. May the gods help you if you are using Internet Explorer on any machine! Otherwise, if this site does not look right on your browser, please let me know what browser you are using (and what version and on what computer). Thanks!
"Visual Basic makes the easy things easier. Delphi makes the hard things easy."
-- unknown
Tuesday, September 27, 2005
 
Internet Explorer Doesn't Play Nice
One would think that, as a company that supposedly portrays itself as a leader in technology (and quite a massive company at that) would have an interest in supporting standards so that it could play well with everybody else. Then again, perhaps Microsoft just wants to stand apart from the rest and be its own island. That would be a bad move. If you don't integrate well into the environment, the environment will eventually reject you...without a branch to hold on to.

Come on, Microsoft - play! Play, play, play! Be a pal. Make something that WORKS!

As you can probably tell, I'm tripping over another Microsoft incompatibility. This one is simply a bug. I have been known to say that Microsoft is incompatible with itself, but this time, it simply doesn't work.

Take a look at the following JavaScript function:


function loadScript(src) {
//----------------------------------------------------------
// Dynamically loads in javascript from the specified source
//----------------------------------------------------------
var ID = "dynamiccode";
var ht = document.getElementsByTagName("head")[0];
var e=document.getElementById(ID);
if (e!=null) {
ht.removeChild(e);
delete e;
}
try {
e=document.createElement("script");
e.id=ID;
e.type="text/javascript";
e.src = src;
ht.appendChild(e);
return true;
} catch(err) {
return false;
}
}


This function works. This was the solution to the IE problem. However, this defeats my original objective to some degree (although I think I can make it work). Look at the line "e.src=src;" -- this is what IE needed. I originally had this basic code within an event handler that responded to an asynchronous XMLHttpRequest() call that requested some javascript, and instead of "e.src=src;", I had "e.innerHTML=r2.responseText;". This put the actual javascript code directly into the new script element, rather than simply specifying the source file and having the browser load it in.

IE can't handle that. But Firefox and Safari work just fine that way.

The solution above works on all browsers, and I guess it doesn't really change much now that I think about it. It may even simplify things a bit, since I can specify the proper PHP query in the src parameter rather than having to go through an asynchronous XMLHttpRequest() query to load it in. But this means everything is suspended while the code loads (should be quick, though). However, it also does not require a page refresh, which was the whole objective to begin with.

This web stuff sure consumes a lot of time and head space, having to deal with all these different browser quirks! It's not like the old days when I could learn the basics of a language overnight. I'm not sure I can fit most of this stuff in my head (between JavaScript, ActionScript, CSS, XHTML, XML, XPath, Perl, PHP, Linux and all these damn browser issues, I'm just having a hell of a time keeping everything straight. But...I suppose I'll get there one of these days.

Wagon ho!

UPDATE:
UGH! This is not a complete solution. The problem with specifying e.src=src; is that this triggers an asynchronous load behind the scenes for which there is no event handler available (that I know of). This means I can't simply assign e.src=src; and then immediately call a function that is in the file being loaded...because it will not be loaded, yet. If IE would just allow me to set e.innerHTML=r2.responseText; like in *my* asynchronous XMLHttpRequest() handler, then I *could* simply turn right around and call a function that I just loaded - because it would actually be loaded!

Curses, Microsoft again!

posted by Bill  # 1:53 PM