Short answer: you cannot and are still platform independent. Most browsers simply do not allow javascript to manipulate the file system.
However, you could get away with some hackers for a particular platform. For example, IE offers an execCommand function that you can use to call SaveAs. If you did this in an IFrame that had data that you wanted to save, you can make it work, but only in IE. Other options (again, I'm going to install Microsoft here) include this Silverlight hack or ActiveX controls.
I think that for full compatibility with the platform you just have to suck it and provide a server-side boot option.
[Change] Oops! When I went looking for links, I did not do due diligence. It turns out that the Silverlight hack I'm connected to has a server component. Sounds like you're pretty SOL.
[Edit2] I found a good summary of browser compatibility for execCommand here . Although it lists question marks for the saveas command, this may be a good way for you. Worth a try, maybe?
[Edit3] Well, I decided to make a proof of concept of the approach that I proposed, and I have something pretty simple in IE. Unfortunately, I proved that this approach will not work for Firefox and does not seem to work in Chrome / Safari. So it is very platform dependent. But it works! Here is the full working page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Javascript File Saver</title> <script type="text/javascript"> function PageLoad() { var fdoc = window.frames["Frame"].document; fdoc.body.appendChild(fdoc.createTextNode("foo,bar,baz")); } function Save() { var fdoc = window.frames["Frame"].document; fdoc.execCommand("SaveAs", true); } </script> </head> <body onload="PageLoad();"> <h2>Javascript File Saver</h2> <iframe id="Frame" style="width: 400px;">Noframe</iframe><br /> <button onclick="Save();">Save</button> </body> </html>
source share