Cookieの使用例(取り出し)
Modified: 26 Dec 1997
このページを開くと、あなたのPCに登録していた、Cookie情報が取り出せます。
設定してある JavaScript
以下のように、前のページで説明した以下のJavaScriptがこのページに実際に設定されています。
<script language="javascript">
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";",offset)
if (end == -1)
end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
}
}document.write(getCookie("tomo"));
取り出して、表示するプログラムです。
</script>
これが取り出した文字列です。
document.write(getCookie("tomo")); で、tomoという名前をgetCookieに与えて、返ってきた文字列を、document.write で表示しています。