Skip navigation.

exploreopera

| Help

Sign up | Help

real *nix devs don't test in IE

, ,

Over at basket.kde.org they are understandably Windows-averse. I guess their website is not exactly targeted at IE users, but even so some cross-browser testing would uncover bugs and errors in their JS. Snippet:

    // Cross-browser implementation of element.addEventListener()
    function addEventListener(element, type, expression, bubbling) {
     bubbling = bubbling || false;
     if (window.addEventListener) { // Standard
      element.addEventListener(type, expression, bubbling);
      return true;
     } else if (window.attachEvent) { // IE
      element.attachEvent('on' + type, expression);
      return true;
     } else return false;
    }


Whoever wrote that obviously is confused about event bubbling versus event capturing (luckily it defaults to a sensible false!) but the main problem with this code is the line

if (window.addEventListener) { // Standard


Um, no, what you are seeing there is not the W3C standardised window.addEventListener1. You're actually checking for the existence of this very function - the one we're inside when we hit that statement. Naturally IE chokes on the next line and no event handlers are added. (If you ask, it should read if(element.addEventListener).)

So - a slick, good-looking production site that wasn't tested with IE - what a rarity! p:

Edit - note 1: well, actually W3C didn't specify addEventListener for window in the first place, it remains a Gecko extension like I've complained about earlier so the comment "// Standard" is doubly wrong..

getYear. No, not that year!interesting jQuery stuff

Comments

avatar
and in opera, I can't get the top menu to work.

EDIT: and if you hover over the feature screenshots, the magnified version that should pop up right where the mouse is actually appears at the very bottom of the page. Too bad if that part is not shown on the screen at the moment.

Hope the program works better than their site.

By WildEnte, # 17. February 2007, 18:26:07

avatar
Hey thanks WildEnte, I didn't notice the top menu being broken. Looks like a CSS issue since it works if you turn styles off. I've filed it as bug 252843.

The feature screenshots problem is what I actually was investigating. The site tries to position the screenshots by reading "x" and "y" properties from the IMG element you hover. I don't know why IMG elements (only?!) have .x and .y in Firefox, it looks like a Netscape 4 feature they've kept for some reason..?

By hallvors, # 18. February 2007, 14:07:48

avatar
JavaScript: The World's Most Misunderstood Programming Language

It would have helped in this case if the global object had a more accurate name. It isn't apparent to beginners that objects created in the global namespace are added as properties to an object named "window".

By HeroreV, # 18. February 2007, 21:16:03

avatar

Originally posted by WildEnte:

and in opera, I can't get the top menu to work.
Same issue as wordpress. Floated links with big margin-bottom.

By xErath, # 19. February 2007, 08:41:42

avatar
Basically treating IE's event-model as a drop-in replacement for w3c's event-model is dead wrong. This approach will only work for very simple cases, else you will soon fall prey to the many disadvantages of IE's model - the lack of proper scoping for the executioncontext of the handler being one of them.

Also note that IE/Mac doesn't support either addEventListener or attachEvent

By crisp, # 19. February 2007, 22:59:13

avatar
Oh the shame. I read it 3 times and then gave up looking for the IE bug (I got the bubbling one). As soon as I read your comments, I realised the function name. What can I say? You know the more you read something, the more you don't look at what you're reading, take it from someone whose job involves proof reading. Can't see the wood for the trees. :faint:

By tarquinwj, # 1. March 2007, 21:48:48

Write a comment

You must be logged in to write a comment. if you're not a registered member, please sign up.