Automatically save a file and then download using HTML5

RichardC11

Bit poster
We have a published application and we do not want users storing files on our server. Also, our users just get confused using the HTML5 download feature. In our application , its easy to auto export a file when the user clicks on an icon. But my question is , is there a way to auto download it for the user to their download folder like other we apps do without the users having to do it ? Thanks Richard
 
OK, creating a data: URI definitely does the trick for me, thanks to Matthew and Dennkster pointing that option out! Here is basically how I do it:

1) get all the content into a string called "content" (e.g. by creating it there initially or by reading innerHTML of the tag of an already built page).

2) Build the data URI:

uriContent = "data:application/octet-stream," + encodeURIComponent(content);
There will be length limitations depending on browser type etc., but e.g. Firefox 3.6.12 works until at least 256k. Encoding in Base64 instead using encodeURIComponent might make things more efficient, but for me that was ok.

3) open a new window and "redirect" it to this URI prompts for a download location of my JavaScript generated page:

newWindow = window.open(uriContent, 'neuesDokument');
That's it.
 
Back
Top