[新着] Webテンプレートを仮オープンしました
まずwriteCookie関数を有効期限が指定できるように修正し,
function writeCookie(cName, cBody, dtExpires)
{
if(dtExpires == null)
dtExpires = new Date(2050, 12, 31, 23, 59, 59);
//クッキーに書き込み
temporary = cName + "=" + escape(cBody) + ";" + "expires=" + dtExpires.toGMTString() + ";";
document.cookie = temporary;// + "expires=Fri, 31-Dec-2050 23:59:59 GMT;";
return true;
}
次にページ全体の必要な項目を一括でクッキーに書き込むsetCookie関数にも有効期限の指定が可能なよう修正を施し,
function setCookie(dtExpires)
{
if (document.getElementById)
{
while (count < tId.length)
{
//登録されたテキストボックスの内容を記録
tValue = document.getElementById(tId[count]).getAttribute("value");
writeCookie(tId[count], tValue, dtExpires);
count ++;
}
}
count = 0;
return true;
}
後はdeleteCookie関数を新規作成し,その中で現在時刻より1ミリ秒古い有効期限を引数にsetCookieを呼び出せば良い.
function deleteCookie()
{
var dt = new Date();
dt.setTime(dt.getTime()-1);
setCookie(dt);
}