Category Archives: Open Source

What the hell, IE….

So last night I was bitten by a very unexpected behavior in the IE JavaScript engine (IE7, specifically, but I would suspect it’s present in all the other versions).

I have a function that iterates through the characters in a string trying to align them with those from another string. I was doing this with a for loop from 0 through “length – 1” and then pulling out the pertinent character from the string using the indexer, e.g.

for (var c = 0; c < myString.length; c++) {
    alert("char at index " + c + " was: " + myString[c]);

This seemed to work fine in all of my initial tests and works like a charm in Firefox.  However, when I flipped back to IE7 to run my JSUnit tests there as well, I saw about 7 errors in my results.  Turns out it was an error from when the string was a single character, e.g. “x”.  From an object perspective, JavaScript still knows it’s a string because all of the string methods are available.  However, use of the indexer, e.g. myString[c], caused it to blow up, saying that myString[c] was undefined.

My assumption here is that, in IE, the indexer syntax actually tries to retrieve the index from its internal data structure (i.e. char[]) rather than its JS representation (i.e. String).  However, it seems that when the string is only one character long, its internal representation is just a plain ole char rather than a char array.  Very odd!

Any which way, this was easily worked around by using the string methods instead:

for (var c = 0; c &lt; myString.length; c++) {
    alert("char at index " + c + " was: " + myString.substring(c, c + 1));
Comments Off on What the hell, IE….

Posted by on 2009-11-26 in Browsers, IE7, JavaScript, jWalker, Open Source



TreeWalker: The ultimate DOM traversal provider

The W3C’s DOM Level 2 calls for the existence of a JavaScript class by the name of TreeWalker, which all DOM Level 2-compliant browsers (amongst the modern ones, this is all but the IE browsers) have successfully provided. But wouldn’t it be nice to have a TreeWalker available in IE too? This is the question that was raised at work during a story with very intense JavaScript requirements. And so, I set out to build a cross-browser TreeWalker (obviously leveraging the native TreeWalker when available). I blew through a number of methods easily (parentNode(), firstChild(), lastChild(), previousSibling(), nextSibling()), but had to call it quits for the night when I got to previousNode() and nextNode()… much too complicated to think about at the late hour. I did get some confirmation by looking at Mozile’s (Mozilla In-Line Editor) TreeWalker JS (

Looks like they also have some JS files in the same folder ( and to give IE ranges/selections the capabilities of a W3C Range and the Mozilla Selection object, respectively, that I may have to peek at to see if I can refactor any of the RangeInformation class I put together to wrap ranges in a mostly cross-browser fashion.

Along with the Selection library I’ve recently created, I’d love to publish a copy of the TreeWalker to the open source world. We’ll see….

Upon second inspection the next day, it turned out that parentNode, firstChild, lastChild, nextSibling, previousSibling were all actually harder methods than I had given them credit for, and nextNode and previousNode were actually the easy ones. The complications come from the whole “logical view” as defined in the W3C spec for DOM Traversal (DOM level 2) that features the TreeWalker.

Comments Off on TreeWalker: The ultimate DOM traversal provider

Posted by on 2009-10-29 in JavaScript, jWalker, Open Source


It’s a new dawn, it’s a new day, it’s a new life…

And I’m feeeeeeeeeeling good!

Officially conquered the non-IE browsers today, including the highlighting feature.  Struggled with the implementation of the highlighting feature in IE, but got the barebones of it working by the end of the day.  The IE implementation, however, has an odd intermittent bug that I haven’t quite nailed down reproduction steps for yet that basically boils down to a character offset being like 5-6 characters off — completely unacceptable in the final implementation, of course.

Going to try to work that one out tonight so that I can show off the prototype tomorrow (per my manager and director’s individual requests).

There are unresolved issues in all browsers, mainly the “line break” dilemma.

Update #1:
Turns out this has to do with moving a TextRange along. If you want to move by characters and the next character (or first character to be in the range) is a space, it gets all screwed up. Investigating workarounds…. 

Update #2:
Came up with a [thus far] consistently working hack of a workaround. Basically, when the range’s selection and the currentNode’s nodeValue do not match, I recollapse to the start and then try to grab the whole nodeValue plus an arbitrary amount of characters (currently 10) to push the buffer along farther. Once it’s moved, I then see how many characters the range encompasses and then move the end point backward by the difference in the expected range versus actual range.

The more annoying part about the TextRange.move/moveStart/moveEnd functions is that they are supposed to return the actual number of characters moved. Turns out they just seem to repeat back the number of characters they were supposed to move (presumably unless you are at the end of the document)… with the padding I added, mine was moving 3 less characters than it should have, but still reporting that it moved the whole span.

Comments Off on It’s a new dawn, it’s a new day, it’s a new life…

Posted by on 2009-09-08 in JavaScript, jWalker, Open Source


Do your worst, Firefox!

Argh, another night of coercing the non-IE browsers’ JavaScript engines into doing my bidding.  Getting ever closer now… pretty soon this spike will be worthy of being called a successful first crack at a real implementation.  I’ll have to add a slew of JSUnit tests before declaring it as such, though!

Comments Off on Do your worst, Firefox!

Posted by on 2009-09-08 in JavaScript, jWalker, Open Source


What’s new?

Currently working on:

  • Advanced cross-browser “find” engine in JavaScript (ETA: ?)
Comments Off on What’s new?

Posted by on 2009-09-03 in JavaScript, jWalker, Open Source