Archive for September, 2008

Testing JavaScript in IE

Thursday, September 18th, 2008
Are libraries guns in the hands of children?

Image by Friedcell via Flickr

As nowadays less and less development goes on in Internet Explorer and the versions that are currently available and widely used have some quirks — to be fair they are by the book and others aren’t — I’m starting this post to have a list of stuff that you need to keep in mind if you don’t want problems when testing in IE.

  1. Trailing comma in object literals

    This is very common in multiline object definitions. someObject = {a:17,b:19,}; looks wrong but when you have a newline after everything it’s hard to find. Firefox lets it be, IE breaks silently. This one is easy to catch with JSLint.

  2. String is not an array

    Even though many languages treat it this way. Using str[i].charCodeAt() breaks while str.charCodeAt(i) doesn’t.

  3. Element ownership matters.

    This means that you have to take care when creating elements and attaching them to different documents. If you’re using jQuery beware – jQuery(someElement).append(someHtml); is ok since it will check what the owner document is but jQuery(someHtml).appendTo(someElement); might break if execution and someElement are in different documents. You can use jQuery(someHtml, someElement.ownerDocument).appendTo(someElement); though.

What I do before testing in any browser other than Firefox (Opera is sometimes even stricter) is to check with JSLint how damaged the code is. It will catch all the weirdly written code that might break a browser. And it catches that trailing comma I mentioned.

I’m quite sure the list should be longer but these are the things I encountered in the last few days. When I find more I’ll add them to the list. If you know any that are not on the list add a comment.

Reblog this post [with Zemanta]

Undocumented jQuery constructor

Wednesday, September 17th, 2008

In jQuery it is possible to create nodes in a foreign document by calling jQuery('<div>sample html</div>', foreignElement.ownerDocument);. If somebody documented this I wouldn’t have lost the last hour or so.

This is why I like wiki style documentation.

Reblog this post [with Zemanta]

Levels of government

Tuesday, September 9th, 2008
Overview of Piran, Slovenia
Image via Wikipedia

Just now the chief of Slovenian Police (about 10.000 employees according to their website) said that he cannot be held responsible for a thing that a guy 20 levels below him did wrong while talking about Slovenian Interpol not responding to an Austrian Interpol request within a year.

Funny – while working at Parsek I worked on the Cisco Systems Slovenia website. If I recollect correctly our contact at Cisco Slovenia was only about 7 or 8 steps from the CEO of the company which has about 66.000 employees (according to Wikipedia).

Reblog this post [with Zemanta]

Dear Opera guys…

Tuesday, September 2nd, 2008
Large bookcase #1, 3rd shelfImage by vjl via Flickr

Can you please tell me how to add external stylesheets with JavaScript? I’m trying to add them by creating a link element with a rel=”stylesheet”, type=”text/css” and a valid href and then appending this to the head element but it doesn’t seem to work. I’m quite sure my css files are good since when stripped down they only contain body {background-color:#ff0000;}.

It’d be great if you could post a solution because I really don’t want to spend another hour thinking about this – I already spent four and I got nowhere.

Reblog this post [with Zemanta]