Long headline! Anyway, this is a problem I’ve encountered more than once. When exporting data from a webpage to a .csv file I usaually create it on the server side using a servlet.
However, If the data is already stored in the browser, you don’t want an extra server request (especially if you’ve manipulated the data on the client).
The first lead came from this post. It explains how to open a separate window with csv content. But how to get the “Save As” dialog? After some searching I found tips about using “data URL” and finally found the solution.
The essentials of my test code:
So basically, pressing the “asdf” button creates the data URL and then the link “test” opens the csv (with save-as dialog). Havn’t tried it in IE, but I’ve read that it’s not going to work.
Questions? Feedback? Feel free to comment!