Java Script memo


更新日を表示


サーバの環境によって正しく表示されない場合があるかも.

<SCRIPT LANGUAGE="JavaScript">
<!--
update = new Date(document.lastModified)
theMonth = update.getMonth() + 1
theDate = update.getDate()
theYear = update.getYear()
if (navigator.appName == 'Netscape') {
theYear = theYear + 1900
}
document.writeln('最終更新' + theYear + '年' + theMonth + '月' + theDate + '日')
// -->
</SCRIPT>

Home

ブラウザから得られる情報

window.navigator オブジェクトを使う. ブラウザによって情報が違う.
IE6Mozilla1.3b
appCodeName
appName
appMinorVersion
cpuClass
platform
plugins
opsProfile
userProfile
systemLanguage
userLanguage
appVersion
userAgent
onLine
cookieEnabled
mimeTypes
platform
appName
appCodeName
appVersion
language
mimeTypes
oscpu
vendor
vendorSub
product
productSub
plugins
securityPolicy
userAgent
cookieEnabled
javaEnabled
taintEnabled
preference
実行例
Home

Cookie クッキー

document.cookie オブジェクトを使う. CookieはURIごとの設定なので,同じディレクトリにあるファイルには 毎回送信してしまうので注意.たとえばこのページでセットしたCookieは index.htmlからでも読み込める.

Cookieをセットするとき

document.cookie = "NAME=VALUE; expires=日付;"
NAME:適当な名前
VALUE:設定したい値
日付:有効期限 Wdy, DD-Mon-YY HH:MM:SS GMT

複数個の値をセットするとときは,document.cookie = ""; を繰り返す.

Cookieを消すときは有効期限を過去にする.
有効期限を指定しないとブラウザを閉じるまでが期限になる.

なんとなく作ってみたソース.正しいかは不明.問題あったら教えてください. いくつも値をセットしたい場合は setCookie() を何回もよんでください.
<SCRIPT LANGUAGE="JavaScript">
<!-- 
function setCookie(key, val){
	cookiestr = key + '=' + escape(val) +';';
	cookiestr += 'expires=Tue, 22-Feb-2022 22:22:22 GMT';
	document.cookie = cookiestr;
}
function getCookie(key){
	key +='=.+?;';
	cookiestr = document.cookie + ';';
	re = new RegExp(key, "i");
	keystr = cookiestr.match(re);
	keystr = " " + keystr;
	from = keystr.indexOf('=');
	to = keystr.length;
	from++;
	to--;
	returnstr = keystr.substring(from, to);
	returnstr = unescape(returnstr);
	return returnstr;
}
function removeCookie(key){
	document.cookie = key + "=;expires=Tue, 22-Feb-2000 22:22:22 GMT;";
}
//  -->
</SCRIPT>

Home