Self modifying html-JavaScript file

守給你的承諾、 提交于 2019-12-01 05:15:38
LarsH

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:

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. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!