开发者

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

开发者 https://www.devze.com 2023-03-30 17:55 出处:网络
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 onl开发者_如何学Cy view it on the chrome browser itself.

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 onl开发者_如何学Cy 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号