 |
|
|  |
| textarea에 입력된 텍스트를 쿠키로 저장합니다 |
|
|
 |
19년 전 |
입력창에 텍스트를 입력후 save text 버튼을 클릭하면 쿠키에 해당 텍스트를 저장하여 다음번에 이 페지이에 접속했을때 입력된 내용을 그대로 디스플레이 합니다.
<HTML>
<HEAD>
<title>http://www.xtx.kr</title>
<script>
function ReadCookie (Name)
{
var search = Name + "="
if (document.cookie.length > 0)
{
offset = document.cookie.indexOf(search)
if (offset != -1)
{
offset += search.length
end = document.cookie.indexOf(";", offset)
if (end == -1)
end = document.cookie.length
return (document.cookie.substring(offset, end))
}
else
return ("");
}
else
return ("");
}
function WriteCookie (cookieName, cookieValue, expiry)
{
var expDate = new Date();
expDate.setTime (expDate.getTime() + expiry);
document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString() + "; path=/";
}
function getCookies()
{
document.noteForm.note.value = unescape(ReadCookie("note"));
}
</script>
</head>
<body>
<form NAME="noteForm">
<textarea ROWS="5" COLS="40" NAME="note" WRAP="VIRTUAL"></textarea><br>
<input TYPE="button" VALUE="Save Text" onClick="WriteCookie('note', document.noteForm.note.value, 2678400000)">
<INPUT TYPE="button" VALUE="새로고침" onClick='parent.location="javascript:location.reload()"'>
</form>
<script>
window.onload=function() { getCookies(); }
</script> |
|
추천 : 496 |
추천
목록
|
|
|  |
|