One possible way to do this is to use Downloadify. It is ...
"a javascript and Flash library that enables the creation and download of text files without server interaction."
You can see a working example here. Unfortunately I don't believe there is anyway to do this natively across legacy browsers.