将Javascript变量的内容下载为命名文件 [英] Download the contents of a Javascript variable as a named file

查看:96
本文介绍了将Javascript变量的内容下载为命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Javascript变量中的文件的内容。当用户点击某些东西(链接,按钮等)时,我想要保存为对话框以我的代码指定的文件名显示,当用户点击保存时,Javascript变量的内容将保存在文件中



我知道如何使用服务器端代码,但这不是这个应用程序的选项。



我已经看到与StackOverflow有关的几个对话与这个问题有关,并且遇到困难,所以我在这个讨论中鼓励创造性思维:)

解决方案

不能说这是我的想法(我发现它所有地方的),但是您是否尝试过 Downloadify ?它只能在最现代的浏览器中运行,但如果没有可用的服务器端组件,那么您真的不用选择。


I have the contents of a file in a Javascript variable. When the user clicks something (link, button, etc.) I want the "save as" dialog to appear with a filename specified by my code and when the user clicks "save", the contents of the Javascript variable are saved in the file.

I know how to do this using server-side code but that is not an option for this application.

I've seen several conversations on StackOverflow related to this issue and the difficulties surrounding it so I'm placing a bounty on this one to encourage creative thinking :)

解决方案

Can't really say that this is my idea (I found it here of all places), but have you tried Downloadify? It will only work in the most modern browsers, but you don't really have a choice if you have no server-side component available.

这篇关于将Javascript变量的内容下载为命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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