JavaScript 쿠키의 만료 옵션은 선택 사항입니다. "expires" 속성은 선택 사항입니다. 이 속성에 유효한 날짜 또는 시간을 제공하면 쿠키가 지정된 날짜 또는 시간에 만료되고 그 이후에는 쿠키 값에 액세스할 수 없습니다.
예시
만료 날짜가 없는 JavaScript 쿠키를 설정하려면 다음 코드를 실행하십시오 -
라이브 데모
<html>
<head>
<script>
<!--
function ReadCookie() {
var allcookies = document.cookie;
document.write ("All Cookies : " + allcookies );
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
// Now take key value pair out of this array
for(var i=0; i<cookiearray.length; i++) {
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
document.write ("Key is : " + name + " and Value is : " + value);
}
}
//-->
</script>
</head>
<body>
<form name="myform" action="">
<p> click the following button and see the result:</p>
<input type="button" value="Get Cookie" onclick="ReadCookie()"/>
</form>
</body>
</html>