만료 날짜를 설정하고 쿠키 내에 만료 날짜를 저장하여 현재 브라우저 세션 이상으로 쿠키의 수명을 연장합니다. 이는 'expires' 속성을 날짜 및 시간으로 설정하여 수행할 수 있습니다.
예
다음 예를 실행하여 쿠키의 만료 날짜를 1개월로 설정할 수 있습니다. −
<html>
<head>
<script>
<!--
function WriteCookie() {
var now = new Date();
now.setMonth( now.getMonth() + 1 );
cookievalue = escape(document.myform.customer.value) + ";"
document.cookie="name=" + cookievalue;
document.cookie = "expires=" + now.toUTCString() + ";"
document.write ("Setting Cookies : " + "name=" + cookievalue );
}
//-->
</script>
</head>
<body>
<form name="myform" action="">
Enter name: <input type="text" name="customer"/>
<input type="button" value="Set Cookie" onclick="WriteCookie()"/>
</form>
</body>
</html>