読者です 読者をやめる 読者になる 読者になる

リアルタイムにクッキーを表示し続けるHTML

JavaScript

現在のクッキーの値を0.5秒ごとに表示します。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja-JP" lang="ja-JP">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Watch Cookies</title>
</head>
<body>
<p id="main"></p>
<script type="text/javascript">
//<[CDATA[

function get_cookies() {
	var result = "";
	if (document.cookie) {
		var cookies = document.cookie.split("; ");
		for	(var i = 0; i < cookies.length; i++) {
			var	tokens = cookies[i].split("=");
			var n = tokens[0];
			var v = unescape(tokens[1]);
			result += n + " = " + v + "<br/>\n";
		}
	}
	return result;
}

function update_display() {
	var c = get_cookies();
	c = new Date() + "<br/><br/>\n" + c;
	var e = document.getElementById("main");
	e.innerHTML = c;
}

update_display();
timer = setTimeout(timer_handler, 500);

function timer_handler() {
	update_display();
	timer = setTimeout(timer_handler, 500);
}

//]]>
</script>
</body>
</html>