East of the Sun, West of the Moon

2004/10/28

Javascript, love or hate

Filed under: Software — Erwin @ 10:19 pm

Mostly I hate it. I think. It’s quite handy to spice up a webpage with little bits of javascript, like auto-submit pull-down menus and such, but once you get beyond trivial, you find out that what you want can be done, sure, but only if you focus on one particular browser, browser version, or platform. There are differences between IE javascript and Netscape/Mozilla/Firefox javascript that are so pointless, it’s painful to read about it. The same IE browser behaves differently on a Mac or a Windows PC because they apparently had two different teams working on something that has otherwise an identical version number. There are things you can do with the Gecko engine that can’t be done with IE javascript, and vice versa. Oh, and then there’s other browsers that just lack both ways, which isn’t a particularly brilliant compromise, really.

Today’s (and yesterday’s) fun was with figuring out the cursor position in a textarea. It can be done with the Gecko engine. In fact it’s bloody easy, you just query the start/end position of the marked text. If they are the same that’s where the cursor is, if not, you’re dealing with a selected piece of text. Then there’s IE. Oh yes. I don’t think they could possibly have made it any more difficult, if they had tried. Why they didn’t simply add the same attributes that Gecko has? No idea. Stubborness, perhaps. The most annoying part is that in IE you have to be really careful or you can really mess with people’s heads and end up modifying the textarea contents just because you’re trying to figure out where the cursor is! And then my (still) favourite browser, Opera. It doesn’t have either one of these methods available. So at the best you can add text at the end of the textarea contents, and pretend that’s useful. I really hope they’ll choose the sane Gecko approach in their next version but I’m not holding my breath.

Powered by WordPress