简体   繁体   English

自修改html-JavaScript文件

[英]Self modifying html-JavaScript file

I would like to have a html file with JavaScript, which (file) is able to modify its context. 我想有一个带有JavaScript的html文件,其中(文件)能够修改其上下文。 In more details, I imagine it like that. 更多细节,我想象它。 I have a html file, which I open with a browser. 我有一个html文件,我用浏览器打开。 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. 因此,表单的上下文保存在html文件中的某处。 What is the easiest and stable way to do that? 最简单,最稳定的方法是什么?

TiddlyWiki saves all its content to a new, local html-with-javascript file in browser-specific ways. TiddlyWiki以浏览器特定的方式将其所有内容保存到新的本地html-with-javascript文件中。 This is because writing to the local hard drive is not normally allowed in javascript, for security reasons. 这是因为出于安全原因,通常不允许在javascript中写入本地硬盘驱动器。 If you're interested in specifically how TiddlyWiki writes the file, check the source code , starting with: 如果您对TiddlyWiki如何编写文件感兴趣,请查看源代码 ,从以下开始:

function saveFile(fileUrl,content)
{
    var r = mozillaSaveFile(fileUrl,content);
    if(!r)
        r = ieSaveFile(fileUrl,content);
    if(!r)
        r = javaSaveFile(fileUrl,content);
    return r;
}

This requires the user to explicitly override security warnings. 这要求用户明确覆盖安全警告。 When I tried it in Firefox, I had to do so several times. 当我在Firefox中尝试它时,我不得不这样做几次。 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; 正如其他人所说,更好的想法是使用客户端存储,例如HTML 5中的新功能(在较新的浏览器中可用),或者更便携的库,例如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. 或者更好的是, YUI的StorageUtility ,它抽象到更高的级别,并使用HTML 5,Google Gears或SWF,具体取决于可用的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM