简体   繁体   中英

Download a text file created using HTML5 filespace api using javascript on chrome

I am trying to download a text file that i created using the file space api on chrome. I am unable to download it. I can only view it on the chrome browser itself.

location.href = fileEntry.toURL();

That is the line of code i currently use to download it.

Could i use content-disposition to force download a .txt file? if so, how?

Check out the FileSaver interface: http://www.w3.org/TR/file-writer-api/#the-filesaver-interface .

Here's a sample that does what you want: http://oftn.org/projects/FileSaver.js/demo/

Here's an HTML5Rocks post that describes usage in more detail: http://updates.html5rocks.com/2011/08/Saving-generated-files-on-the-client-side

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM