自修改 html-JavaScript 文件
我想要一个带有 JavaScript 的 html 文件,该文件(文件)能够修改其上下文。更详细地说,我是这样想象的。我有一个 html 文件,我用浏览器打开它。我在那里有一个文本区域,我可以在其中输入文本并按提交按钮。因此,表单的上下文保存在 html 文件中的某个位置。最简单且稳定的方法是什么?
I would like to have a html file with JavaScript, which (file) is able to modify its context. In more details, I imagine it like that. I have a html file, which I open with a browser. I have a text area there where I type my text and press submit button. As a result of that, the context of the form saved somewhere in the html file. What is the easiest and stable way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TiddlyWiki 以特定于浏览器的方式将其所有内容保存到新的本地 html-with-javascript 文件中。这是因为出于安全原因,JavaScript 中通常不允许写入本地硬盘驱动器。如果您对 TiddlyWiki 如何编写文件特别感兴趣,请查看源代码,从:
这要求用户明确忽略安全警告。当我在 Firefox 中尝试时,我不得不这样做好几次。这不是一个好的做法,因为用户会非常想检查“记住此决定”,并可能在将来将自己暴露在恶意软件中。
正如其他人所说,更好的想法是使用客户端存储,例如 HTML 5 中的新功能(在较新的浏览器中可用),或者更便携的库,例如 Google Gears;或者也许更好,YUI 的 StorageUtility,它抽象到更高的级别并使用 HTML 5 、Google Gears 或 SWF,具体取决于可用的内容。
TiddlyWiki saves all its content to a new, local html-with-javascript file in browser-specific ways. This is because writing to the local hard drive is not normally allowed in javascript, for security reasons. If you're interested in specifically how TiddlyWiki writes the file, check the source code, starting with:
This requires the user to explicitly override security warnings. When I tried it in Firefox, I had to do so several times. This is not good practice, as a user would be sorely tempted to check "Remember this decision" and potentially expose themselves to malware in the future.
As someone else said, a better idea is to use client-side storage such as the new features in HTML 5 (available in newer browsers), or a more portable library such as Google Gears; or perhaps better, YUI's StorageUtility, which abstracts to a higher level and uses either HTML 5, Google Gears, or SWF depending on what's available.