How to generate a file for download in a Google Chrome Extension?

后端 未结 3 514
长情又很酷
长情又很酷 2020-12-29 15:33

I want to generate a CSV file as the result of some user interactions and then prompt the user to download it. How can I do that?

I don\'t think it\'s possible in st

3条回答
  •  长发绾君心
    2020-12-29 16:31

    You can now use HTML5 File API to download a file. It is still in development, but you can use a BlobBuilder and redirect your use to download that file:

    var bb = new BlobBuilder();
    bb.append(csvContents);
    var blob = bb.getBlob(); 
    location.href = window.webkitURL.createObjectURL(blob);
    

    For more information regarding the File API, HTML5Rocks has a great tutorial:

    http://www.html5rocks.com/tutorials/file/filesystem/

提交回复
热议问题