<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Cross Browser Compatibility</title>
        <link>http://www.alexkuo.info/category/6.aspx</link>
        <description>Posts that point out differences between web browsers and their quirks (or bugs).</description>
        <language>en-US</language>
        <copyright>Alex Kuo</copyright>
        <generator>Subtext Version 1.9.4.0</generator>
        <item>
            <title>Script tags and Javascript Arrays in IE and Firefox</title>
            <link>http://alexkuo.info/archive/2007/08/07/40.aspx</link>
            <description>Tonight I was wrapping up a deployment for a feature that was heavily dependent on javascript. After running my first batch of tests on Firefox, everything passed without a hitch. Then I ran my tests on Internet Explorer 7 and.... nothing.. literally a blank page rendered on my screen. Thus began my latest saga of fixing compatibility issues between browsers.&lt;br /&gt;
&lt;br /&gt;
The first problem was that my scripts were either being downloaded and not executing, or were not downloading at all. I checked if the javascript files were being retrieved by using program called &lt;a target="_blank" href="http://www.fiddler2.com"&gt;Fiddler2&lt;/a&gt;. This program intercepts all HTTP requests  and responses from Internet Explorer. After running the program, it confirmed that my files were being downloaded. So, this means the files were not being executed. After staring at my html code which looked like the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 80px; text-align: left;"&gt;...&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;script type='text/javascript' src='/file.js' /&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;....&lt;br /&gt;&lt;/pre&gt;
&lt;br /&gt;
I immediately remembered that Internet Explorer doesn't render javascript references unless you specify the complete tag. Why? I suspect its because I didn't specify the doctype in the html tags. So to fix that problem, I changed the script tag to look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 80px; text-align: left;"&gt;...&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;script type='text/javascript' src='/file.js'&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
However, that was not the end of my javascript problems with Internet Explorer. After running the javascript, I ran into an error regarding an undefined element in an array. My first thought was that this couldn't be. The script ran flawlessly in Firefox. After some debugging, I concluded that the Javascript engine in IE interprets text representations for arrays differently than Firefox. The evidence that lead to this conclusion came from comparing the array length returned in Firefox versus Internet Explorer. Firefox's length was 3, while Internet Explorer's was 4. &lt;br /&gt;
&lt;br /&gt;
My Firefox-only-array looked something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 70px; text-align: left;"&gt;array = [ {id:1,name:'hi'}, {id:2, name:'hello'}, {id:3, name: 'greetings'}, ]&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;br /&gt;
Turns out that last comma in the array throws off Internet Explorer and causes it to increment that length an extra tick. The fix would be to remove that last comma. The fixed code looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="alt2" dir="ltr" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 50px; text-align: left;"&gt;array = [ {id:1,name:'hi'}, {id:2, name:'hello'}, {id:3, name: 'greetings'} ]&lt;br /&gt;&lt;/pre&gt;&lt;img src="http://alexkuo.info/aggbug/40.aspx" width="1" height="1" /&gt;</description>
            <guid>http://alexkuo.info/archive/2007/08/07/40.aspx</guid>
            <pubDate>Tue, 07 Aug 2007 12:10:16 GMT</pubDate>
            <comments>http://alexkuo.info/archive/2007/08/07/40.aspx#feedback</comments>
            <wfw:commentRss>http://alexkuo.info/comments/commentRss/40.aspx</wfw:commentRss>
            <trackback:ping>http://alexkuo.info/services/trackbacks/40.aspx</trackback:ping>
        </item>
    </channel>
</rss>
