Cross Browser Scripting
Recently I have written an ajax tutorial. It was interesting and fairly easy to make since I was mainly using some normal ajax which I had lying around. The main point of the tutorial was to show that it would make a practical website.
The main code for the tutorial was written in a fairly short period of time, then I tried testing the script in Internet Explorer, which I probably should have done earlier. Suffice to say, the script did not function properly in Internet Explorer.
The strange thing about this bug however was that, although it did the same every time the page was loaded, what it did didn’t really make sense. It would run the first ajax request and then would not run any more requests. So my ajax code was correct because it worked but it only ran once. There was no errors according to IE’s debugging stuff. I still do not know why this error happens however I managed to find a solution on the internet. It involved switching round two lines of code.
http.onreadystatechange = handleResponse;
http.open('get', webpage);
Had to be changed to:
http.open('get', webpage);
http.onreadystatechange = handleResponse;
But this should not have been needed. Why should opening a connection change what function was attached to the onreadystatechange event? It doesn’t matter in other browsers, nor the first time the script is run.
The annoying thing was that I spent about 30 minutes trying to fix this, which was a disproportionate time to writing the script. First I thought it was due to the way that I called the function so I spent a while messing around with different ways of doing this, none of which fixed it. I know debugging code takes a while but I don’t see why it should take so long to make it work in another browser which should be implementing javascript in the same way.
There is also a problem when using css and html, and most often your code works properly in everything other than Internet Explorer. Most web developers will tell you this if they have tried developing for multiple browsers with slightly complex things. This is the main reason why I am so pleased with the growing popularity of non IE browsers. Hopefully this will encourage the internet explorer developers to increase compatibility with the W3C’s standards because it is greatly irritating for a web developer.