IE assumes .CSV is HTML, Firefox and Opera get it right. [part 2]
[…continued]
So, I decided to try to write a ‘bookmarklet’ (or ‘favelet’ as they’re sometimes called in the IE world), because I’ve been finding a lot of useful ones lately, and I often find myself throwing javascript into my address bar by hand to modify a particular page’s behavior. Before writing one myself, I searched for a while to see if it’s been done already. I wasn’t able to find any javascript code to transform a page of .CSV data into a more readable form (namely, an HTML table). I did find a CSV Converter page, which lets you paste CSV data into a textarea (or upload a file) and submit it to a CGI script, which returns the data as either HTML tables or WikiMedia format. I first tried writing a bookmarklet to submit the current page’s body to that CGI script.
But that didn’t work so well. Part of the problem, from what I could see, is that when IE rendered the page as HTML, the carriage-return/line-feed characters were replaced by a space. This presented a challenge for programatically parsing the CSV text, because now I had to know how many columns existed in the data, so I could figure out where to break the lines, so the table would have more than one row. (My earliest attempts produced a table with only one row, with LOTS of columns)
So, I ended up cheating a little bit, and requiring that the data in the first column on the second row will always be ‘IE’. Other than that, the bookmarklet I created can handle more columnns in the future, automatically.
Right click this link and add to Favorites/Bookmarks
If you’d just like to look at the code, click here to see it in a more readable form.
Well, wouldn’t you know it… this bookmarklet works in IE 5.01, IE 5.5, Firefox 1.07, and Opera 8.5, but NOT IN IE 6.0. The exact same browser whose shortcomings I was trying to work around. (The earlier IE versions also made the CSV == HTML assumption, but at least my bookmarklet worked in those versions). IE 6.0 did not generate any javascript errors when running the script, nor did it pop up its little security warning bar, or any other visible behavior. It just sat there.
I give up. Stupid IE.
To see the behavior (or lack thereof) of the bookmarklets above:
- right click it and add it to your favorites/bookmarks
- go to one of the CSV pages (all 3 files are the same–they just have different extensions):
- select the bookmarklet from your favorites/bookmarks list to run the script
Doing this with different browsers will unfortunately yield different behavior. If anyone can suggest how to make it work in IE 6.0, or how to fix it so it doesn’t require ‘IE’ to be the first value on the second line of the CSV file, I’d love to hear about it!


December 2nd, 2005 at 12:22 am
Judging by how much you like Bookmarklets, and typing JavaScript into your location bar to change the page you’re on, you should definitely check out Grease Monkey:
http://greasemonkey.mozdev.org/