Sunday, July 12, 2009

Best practices?: Modifying HTMLCollections in IE

I just ran into a very weird IE quirk, and I'm wondering what the best practice would be regarding it. (I've only tested in IE7; it might show up in other versions.)

Before I had IE installed, I had to modify a form and then find my elements in it to modify them again, and the elements' names were the most convenient way to accomplish the second part. So of course I went for the form.elements collection, and this works fine in Firefox. But not only is this property actually the form itself in IE, the developers apparently didn't read this part of the spec:
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-1019015399
Note: Collections in the HTML DOM are assumed to be live meaning that they are automatically updated when the underlying document is changed.
To demonstrate what this means, I threw together a small test page (post continues below):
<html>
<head>
<title>IE DOM modifications</title>
<script type='text/javascript'
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
<script type="text/javascript">
window.onload = function(){
var form = document.forms.namedItem('test');
var input = document.createElement('input');
input.name = 'foo';
input.type = 'hidden';
input.value = 'bar';
form.appendChild(input);
console.log(form.childNodes[0]);
// form[input.name] = input;
console.log(form['foo']);
console.log(form.elements.namedItem('foo'));
};
</script>
</head>
<body>
<form name="test">

</form>
</body>
</html>

If form[input.name] = input; (a very ugly hack) is commented, the first call to console.log works but the other two don't. Otherwise, the first two work but the last still doesn't.

So here's my question: Is this the best way to workaround this quirk? The idea of form elements being direct properties of the form isn't in the standard, and the standard namedItem function remains broken. I managed to still use namedItem by default, but I really don't like the hack at all.

Here's how I retrieved my element:form.elements.namedItem(name) || form[name]

Friday, June 5, 2009

Pandora stopped working, Firefox's fault?

Pandora suddenly stopped in the middle of a song today. I was afraid it wouldn't ever work again, which would seem to herald the old problems returning and a new laptop purchase. I refreshed the window, same problem. Then I closed Firefox (had to end it in System Monitor) and Pandora was revived. Yay!

Saturday, May 30, 2009

My Ubuntu Adventure

A long time ago, I encountered the open-source movement as a hobbyist programmer (which I still am, unfortunately) and wanted to try Linux out. I found the Debian site, but the instructions were way over my head so I didn't dare touch it. I'm not sure whether I had my laptop at that time, but I was at least expecting to buy one. Some time later, I met a guy named Nathan and we became fast friends. While he had never used Linux, he knew of Ubuntu and suggested that I request a CD. I did, and what a learning experience it's been!

I was completely ignorant of partitions, and I think I resized the one on which Windows XP Professional was pre-installed. Hey, where'd my data go? Over the next year, I had loads of newbie problems and started experiencing really weird bugs:

  • Certain keys would stop working for no apparent reason;[1]

  • Firefox started giving JavaScript errors about ordinary whitespace;[2]

  • Flash would crash Firefox;[3]

  • sound of different types progressively failed until I had almost none left;[4]

  • I tried to fix Apache by reinstalling and apt-get choked - hard;[5]

  • programs compiled from the same source by gcc became inconsistent;[6]

  • diffs contained corrupted data.[7]

So now, even though I was fighting to keep coding, I had run into crippling problems with JavaScript, PHP, and C. Even fixing really basic bugs in GNOME which didn't require testing, I was encumbered by diff's corruption. So now I was reduced to typing (also encumbered) and playing games until I could reinstall.

After I finally got my /home directory backed up correctly, I used fdisk to repartition because I had been warned of the Live CD's "idiosyncrasies" (although I did have to tweak from the CD because of cylinder boundaries). I installed Jaunty and put the data back where it belonged. That messed GNOME up and broke the sudo command[8], both presumably because the data was generated on Intrepid. So for a while I only ran on the Live CD, which uses RAM as hard drive space; that got old really fast, although Google's storage came in handy.

I tried to install Jaunty on another partition, but the Live CD's second option installed it on a very small one that I had intended for something else. I only found out when the JRE required more space than I had. I had to repartition because the second installation made new sections that I didn't want. After figuring out how to work around memory conversion bugs in the Live CD's partition editor, I finally got a clean install.

I installed Jaunty again to get a programming partition, and again on the partition I intend for Windows so I can debug my /home data. All three use the same /home partition so I can easily transfer data. My backup has a profile folder named "chris" as does my main install, so I had to extract without ruining the clean profile. I managed that by renaming the real one "_chris" and copying the extracted data to the temporary installation's profile. The user ids were (I guess) the same for both users, so ownership was automatically transferred.

The other time that I extracted my data, I only ran into problems after restarting. This time, I tried running Pandora, to lighten up my debugging tedium, and it froze Firefox like the bad old days. So now I know two things about the remaining bugs:

  1. They reside in my profile;

  2. they are not all triggered at startup.

This post is intended for two purposes. I would really like to get some help in the comments, as the gurus on Ubuntu Forums seem tired of my queries. I also hope to help the poor Googler who finds my experience all too familiar, and maybe even get whatever bug(s) are behind it fixed.


  1. http://ubuntuforums.org/showthread.php?t=1012239

  2. http://forums.mozillazine.org/viewtopic.php?f=25&t=940905

  3. I didn't make a thread for this case, although this one is related; the above case was later and (I think) cross-browser.

  4. No thread for this one either, but this is related.

  5. http://ubuntuforums.org/showthread.php?t=1038787

  6. http://cboard.cprogramming.com/c-programming/114634-exiting-gtkplus-allowing-cli-continue.html

  7. http://ubuntuforums.org/showthread.php?t=1126698