Thursday, July 2, 2009

IE: Javascript Hitches, Glitches and More!

My last two days in the Laboratory have been about tweaking Javascript so that Internet Explorer understands it. When web programming, rest assured that IE will behave like a juvenile delinquent and demand special treatment; and you my dear, will have to succumb.
But lets not get you more wound up than you already are - with the world of blogs and wikis, you will find your way :)

Here is some of the stuff that I picked up along this odyssey(thats not yet over btw.). I've been foraging for 2 days and I wouldn't want you to do the same!

  • InnerHTML - If you want to say dynamically expand an option list by simply appending to existing innerHTML using += ; IE won't let you. You need to explicitly use a createElement as shown:
var opt = document.createElement("OPTION");
opt.value = "some text"; //use setAttribute
opt.appendChild(document.createTextNode("some text"));
opt.selected = true;

  • The text for an option - notice the
    opt.appendChild(document.createTextNode("some text"));
    line above. If you had simply done
    opt.text= "some text" ;
    IE would have whined.
  • http://www.berniecode.com/blog/2007/03/08/how-to-debug-javascript-with-visual-web-developer-express/ explains how to get a decent debugger running for IE for free! Note: If IE is not set as your default browser, no worries and donot change that setting because IE is not worth it. Just read the comments below the post in the link above.
  • http://www.quirksmode.org/dom/w3c_core.html gives a browser wide comparison of certain Javascript methods and how each browser accounts for them.
  • File uploads in IE - They will fail. :) But not if you set both properties 'enctype' as well as 'encoding' to "multipart/form-data".
Well have a blast! There's probably more coming up since I forsee a lot of IE damage control that I need to do in the next few days.

0 comments: