보통 로그인할때 아이디를 저장하는 기능 입니다.
다음번 로그인 할때 아이디가 자동으로 입력되도록 쿠키로 설정하는 것입니다.
-----------------------------------------------------------------------------
<html>
<head>
<script language="javascript">
function setCookie (name, value, expires) {
document.cookie = name + "=" + escape (value) +
"; path=/; expires=" + expires.toGMTString();
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) { // 쿠키가 설정되어 있다면
offset = document.cookie.indexOf(search)
if (offset != -1) { // 쿠키가 존재하면
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset)
// 쿠키 값의 마지막 위치 인덱스 번호 설정
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
return "";
}
function saveid(form) {
var expdate = new Date();
// 기본적으로 30일동안 기억하게 함. 일수를 조절하려면 * 30에서 숫자를 조절하면 됨
if (form.checksaveid.checked)
expdate.setTime(expdate.getTime() + 1000 * 3600 * 24 * 30); // 30일
else
expdate.setTime(expdate.getTime() - 1); // 쿠키 삭제조건
setCookie("saveid", form.id.value, expdate);
}
function getid(form) {
form.checksaveid.checked = ((form.id.value = getCookie("saveid")) != "");
}
</script>
</head>
<body onLoad="getid(document.mainform)">
<form name=mainform>
아이디 <input type=text name=id>
암호 <input type=password name=pw>
<input type=checkbox name=checksaveid onClick="saveid(this.form)">아이디 기억
</form>
</body>
</html>
"Java Script" 카테고리의 다른 글
[2007/11/10] 최적 해상도보다 사용자해상도가 작을때 경고 후 창 닫기 [2007/11/26] 스크랩 금지된 네이버 블로그와 카페글을 스크랩하고 싶... [2008/07/18] 로그인 할 때 쿠키로 아이디 저장하기 [2008/07/03] 아이프레임 크기 자동조절 [2007/12/19] 영타를 한글로 ^^ [2007/11/08] 부드러운 세로 슬라이드 메뉴~!! [2007/12/19] 작성완료시에만 전송시키기 [2007/12/05] Internet Explorer에서 셀렉트박스와 레이... [2008/01/18] js :: 팝업메뉴 생성하기 [2008/09/10] 부모창에서 사용자가 이동할때 팝업창 자동으로 닫히게 하기





