如何在Google Chrome扩展程序中生成要下载的文件? [英] How to generate a file for download in a Google Chrome Extension?
本文介绍了如何在Google Chrome扩展程序中生成要下载的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要生成一个CSV文件作为一些用户交互的结果,然后提示用户下载它。我怎么能做到这一点?
我不认为这是可能的直JS,但也许Chrome给我一些提升的特权?
<您现在可以使用HTML5 File API
解决方案
/ a>下载文件。它仍在开发中,但您可以使用BlobBuilder并重定向您的下载文件:
var bb = new BlobBuilder ();
bb.append(csvContents);
var blob = bb.getBlob();
location.href = window.webkitURL.createObjectURL(blob);
有关File API的更多信息,HTML5Rocks有一个很棒的教程:
http://www.html5rocks.com/tutorials/file/文件系统/
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 straight JS, but perhaps Chrome gives me some elevated privileges?
解决方案
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/
这篇关于如何在Google Chrome扩展程序中生成要下载的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文