zomgistania

Main page | About | Articles | Previous Posts | Archives

Monday, March 20, 2006

JavaScript/DOM

JavaScript is an often disregarded technique to add a new level of user interaction to webpages.

I used to hate it. Now I love it.
Back in the day, the support for JavaScript was SO different between browsers. Now most browsers support it quite well.

Well enough to do simple things with ease and more difficult things with... well, with more difficulty.


There also seems to be a huge difference in the performance of the JavaScript "engines" in the browsers. Let's take a script which highlights table cells when you point the cursor over one.

1. Find the element where the mouse is
2. Loop through the table to find the position of the element in the table
3. Loop through the table to highlight the horizontal and vertical line of cells where the highlighted cell is
4. Highlight the actual cell too

That works lightning fast in Opera and Firefox. Internet Explorer on the other hand is quite slow.

I know the code I've written isn't very efficient and it could be faster for IE too. I just haven't had the time to go through the algorithms.



There's still one very annoying thing even with the modern browsers' quite equal JavaScript support. COLORS!

Wanna detect a color?


if(x.style.backgroundColor != "#ff0000" && x.style.backgroundColor != "rgb(255, 0, 0)" && x.style.backgroundColor != "blue")

You need 3 different detects.
Shoot me now!

(note: the colors in the example might not all be blue but you get the point)

0 Comments:

Post a Comment

<< Home