Back to feed
Renewal·서른의 생활코딩

Sample Source 5) JavaScript Basic Document Structure: Cookie (1)

NS
normalstory
cover image

Sample Source 5) JavaScript Basic Document Structure: cookie (1)




name :name
expires: date
path :path
domain:URL where cookie matches 
secure:true/falseis used to ask whether to transfer data.

excape:converts to Unicode format.
toGMTString():returns the date converted to string using Greenwich Mean Time.



1) Cookie creation example

<!DOCTYPE html> 

<html> 

<head> 

<meta charset="utf-8"> 

<title>cookie</title>

<script type="text/javascript">

//<![CDATA[

var cookieName="pop_chk";

var cookieValue="pop2010";

today=new Date();

today.setDate(today.getDate()+1);

document.cookie=cookieName+ "=" +escape(cookieValue)+ "; path=/; expires=" +today.toGMTString()+ ";";

// load cookie

document.write(document.cookie+"<br />");

//]]>

</script>

</head>


<body>

Cookie creation complete. 

Tools > Internet Options > Settings > View Files > Last modified date (recent)

</body>

</html>




2) Loading a cookie created in another document, from another document

<!DOCTYPE html> 

<html> 

<head> 

<meta charset="utf-8"> 

<title>cookie</title>

<script type="text/javascript">

//<![CDATA[

// load cookie

document.write(document.cookie+"<br />");

//]]>

</script>

</head>


<body>

Cookie creation complete. 

Tools > Internet Options > Settings > View Files > Last modified date (recent)

위에 스크립트를 보면 쿠키 생성을 안했지만 쿠키는 로컬에 저장되기 때문에

  they can be loaded from external documents.

</body>


</html> 

 

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.

More on the author's page

Keep reading

Renewal

Steadily, for the long haul, without burning out

Mar 31, 2026·9 min
Renewal

Tech-life balance

Feb 7, 2026·3 min
Renewal

Humanality, by Park Jeong-ryeol

Feb 7, 2026·11 min