Javascript:将json数据保存为服务器/用户硬盘上的文件
我开发了一个应用程序,允许用户用信息填写文本字段。我希望他们能够按下一个按钮来创建一个包含数据的文件(一个非常长的数组,其中包含有关他们输入的内容和应该去的位置的信息),以便他们可以在以后重新加载数据。我现在没有服务器,我将此应用程序作为独立的 html 应用程序发送给我的朋友供他们使用,直到我获得 hosing / mySql / 等。 有没有一种方法,当他们点击按钮时,它会获取这些数据(保存为数组,save_data
),将其放入文件中,并基本上从他们的网络浏览器开始下载过程? 后来,我需要研究什么技术才能将其保存到在线用户帐户中?
I have developed an app that allows the user to fill out text fields with information. I want them to be able to press a button that will make a file with data (a really long array with info on what they typed and where it should go) so they can reload the data at a later date. I don't have a server now, and I am sending this app as a standalone html app to my friends for their use until I get hosing / mySql / etc.
Is there a way that when they click on a button it will take this data (saved as an array, save_data
), put it into a file, and basically begin the download process from their web-browser?
And later on, what tech would I need to be looking into to save this into online user accounts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是可能的,但前提是您强制用户使用 Windows 和 Microsoft Internet Explorer。您可以将 html 文件作为 hta 文件发送,该文件可以从硬盘写入和读取数据。
检查 http://msdn.microsoft.com/en -us/library/ms536496%28VS.85%29.aspx
了解更多信息。
hta 文件基本上是一个本地 html 文件,在标头中带有一些额外的标签,并且在本地运行(解释),没有安全限制,就像任何 exe 文件一样。
我不知道如何在这里显示完整的 html 代码(markdown 不适合我),所以如果你想要一个例子:
1 - 创建一个文件 test.hta,包含标准 html、head、body 和 script 标签
2 - 在 head 标签内,插入
3 - 在 body 标签内放置一个带有 onclick="writeText();"
的按钮
4 - 在脚本标签内插入
5 - 保存它,双击它,单击按钮,您将得到一个漂亮的“C:\testhta.txt”文件,其中包含“写入的文本文件”。
It is posible, but only if you force your users to use windows and microsoft internet explorer. You can send the html file as a hta file, wich can write and read from data from the hard disk.
check http://msdn.microsoft.com/en-us/library/ms536496%28VS.85%29.aspx
for more information.
An hta file is basically a local html file with some extra tags in the header, and is run (interpreted) locally without security restrictions, like any exe file.
I don't know how to show the complete html code here,(markdown is not for me), so if you want an example:
1 - create a file test.hta, with the standard html, head, body and script tags
2 - inside head tag, insert
3 - inside body tab put a button with onclick="writeText();"
4 - inside the script tag insert
5 - save it, doubleclick it, click on the button and you will get a nice "C:\testhta.txt" file with 'text file written' in it.
如果您没有服务器,那么就没有...无法根据使用 javascript 动态生成的数据启动文件下载/保存
If you don't have a server, then no ... there is no way to initiate a file download/save based on dynamically generated data with javascript