Chrome扩展程序:“即时”创建的“下载/导出内容” [英] Chrome extension : Download/export content created "on the fly"

查看:140
本文介绍了Chrome扩展程序:“即时”创建的“下载/导出内容”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让用户从扩展中包含的某些数据中即时下载创建的文件,但是我不想在服务器端执行此操作。

I need to let the user to download a file created on the fly from some data contained in the extension, but I don't want to do this server-side.

作为一个现实世界的例子:有一个包含文本hello world的变量。我希望用户能够下载/创建一个包含此类文本的 .TXT 文件。

As a real-world example : There is a variable containing the text "hello world". I want the user to be able to download/create a .TXT file containing such text.

是否可能?

-edited 2010年10月30日 -

-edited Oct 30, 2010-

解决方案到目前为止:

window.saveAs - 不工作

createObjectURL - 工作,但文件名并且其他选项不能自定义

createObjectURL - works, but the filename and other options can't be customized yet

将数据复制到剪贴板 - 工作,但用户需要太多步骤

copy data to clipboard - works, but too many steps are required to the user

创建GoogleDocs文档 - 可以工作,但需要搞砸API和Oauth

create a GoogleDocs document - could work, but needs messing with the API and Oauth

-edited 2011年4月15日

-edited Apr 15, 2011

看起来事情正在改善: https://github.com/eligrey/FileSaver.js

Looks like things are improving: https://github.com/eligrey/FileSaver.js

但Chrome 14+对于文件名仍然有点奇怪。

But Chrome 14+ is still a bit weird about filenames.

推荐答案

我认为唯一的方法是通过flash调用保存对话框,参见 Downloadify 库。

I think the only way is to call save dialog through flash, see Downloadify library.

这篇关于Chrome扩展程序:“即时”创建的“下载/导出内容”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆