Embedded in an XHTML document it looks as follows:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da">
<head>
<title>Demo of Cookies</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="./simpleCookie.js"></script>
</head>
<body>
<h1>Demo of cookies</h1>
<h2>Setup</h2>
<p>
The JavaScript cookie handler is attached as an external
<tt>.js</tt> file. Execution code sequence is in this
document. Please use <tt>View source</tt> to see.
</p>
<p>
<script>
if (existsCookie("counter")) {
document.write("Counter cookie exists");
document.write("<br />value: " + getCookie("counter"));
var cnt = getCookie("counter");
cnt++;
setCookie("counter",cnt);
document.write("<br />New value is: " + cnt);
} else {
document.write("Counter does not exist, create and set to 0");
setCookie("counter",0);
}
</script>
</p>
</body>
</html>