朔用拡張機能開発スレ

ce20ad17 :Anonymous 2010-12-16 21:42
投稿した際、名前とメールと署名の各欄をcookieに記憶
JSONオブジェクト使ってるんでない場合はjson2.jsを使えるようにするか、json使わないように改造するかしてください。

//save "name", "mail", "signature"

initFunc[initFunc.length] = function () {
//alert(document.cookie);
if (document.cookie.search(/form=(.*)/) >= 0) {
var formload = RegExp.$1;
try {
var form = JSON.parse(formload);
document.forms["postarticle"].elements["name"].value = decodeURI(form["name"]);
document.forms["postarticle"].elements["mail"].value = decodeURI(form["mail"]);
document.forms["postarticle"].elements["passwd"].value = decodeURI(form["sign"]);
} catch (err) {
//alert(err);
}
}
function save() {
var name = document.forms["postarticle"].elements["name"].value;
var mail = document.forms["postarticle"].elements["mail"].value;
var sign = document.forms["postarticle"].elements["passwd"].value;
name = encodeURI(name);
mail = encodeURI(mail);
sign = encodeURI(sign);
var form = {"name": name, "mail": mail, "sign": sign};
var formjson = JSON.stringify(form);
var exp = new Date();
exp.setTime(exp.getTime()+1000*60*60*24*32);
var formsave = 'form=' + formjson + '; ' + 'path=/; ' + 'expires=' + exp.toGMTString() + '; ';
document.cookie = formsave;
}
var postarticle = document.getElementById("postarticle");
if (postarticle.addEventListener) {
postarticle.addEventListener("submit", save, false);
} else if (postarticle.attachEvent) {
postarticle.addEventListener("onsubmit", save);
}
};
Powered by shinGETsu.