<script language="JavaScript">
function set ()
{
var expdate = new Date();
expdate.setMonth(expdate.getMonth()+6);
alert("setting cookie \""+form1.txtName.value+"\" to \""+form1.txtValue.value+"\"");
setCookie(form1.txtName.value, form1.txtValue.value, expdate);
}
function get ()
{
alert("getting cookie \""+form1.txtName.value+"\"");
var c = getCookie(form1.txtName.value);
alert( "cookie = "+c );
form1.txtValue.value = c;
}
function getCookie (sCookieName)
{
var sName=sCookieName+"=", ichSt, ichEnd;
var sCookie=document.cookie;
if ( sCookie.length && ( -1 != (ichSt = sCookie.indexOf(sName)) ) )
{
if (-1 == ( ichEnd = sCookie.indexOf(";",ichSt+sName.length) ) )
ichEnd = sCookie.length;
return unescape(sCookie.substring(ichSt+sName.length,ichEnd));
}
return null;
}
function setCookie (sName, vValue)
{
var argv = setCookie.arguments, argc = setCookie.arguments.length;
var sExpDate = (argc > 2) ? "; expires="+argv[2].toGMTString() : "";
var sPath = (argc > 3) ? "; path="+argv[3] : "";
var sDomain = (argc > 4) ? "; domain="+argv[4] : "";
var sSecure = (argc > 5) && argv[5] ? "; secure" : "";
document.cookie = sName + "=" + escape(vValue,0) + sExpDate + sPath + sDomain + sSecure + ";";
}
function deleteCookie (sName)
{
document.cookie = sName + "=" + getCookie(sName) + "; expires=" + (new Date()).toGMTString() + ";";
}
'Developer > JavaScript' 카테고리의 다른 글
How to use multiple window.onload events with external scripts (0) | 2007.05.02 |
---|---|
문자열이 ASCII 코드로만 이루어졌는지 체크하는 함수 (0) | 2007.04.26 |
자바스크립트 단축키 핸들러 - shortcuts.js (0) | 2007.04.20 |