ソース見本
<script language="javascript"> ///////////訪問者のパソコンから情報を取得//////////// function getCookie(key){ tmp=document.cookie+";"; tmp1=tmp.indexOf(key,0); if(tmp1!=-1){ tmp=tmp.substring(tmp1,tmp.length); start=tmp.indexOf("=",0)+1; end=tmp.indexOf(";",start); return(unescape(tmp.substring(start,end))); } return(""); } ///////////訪問者の名前を入力//////////// function putName(){ names=document.f1.na.value; if(names==""||names==null){ names="お客"; } setCookie("GuestName",names); PageGo(0); } ///////////訪問者のパソコンに情報を書き込み//////////// function setCookie(key,val){ tmp=key+"="+escape(val)+";"; tmp+="expires=Fri,31-Dec-2030 23:59:59; "; document.cookie=tmp; } ///////////訪問者の名前を訂正入力//////////// function mentName(){ document.getElementById("in_form").style.display="inline"; } //////////ページを更新する/////// function PageGo(n){ history.go(n); } ///////////訪問者名で歓迎メッセージ//////////// function printName(){ document.write("<center><font size=5 color=#004488>ようこそ「"); document.write("<a href='javascript:mentName()'><b>",names,"</b></a>さん」、 "); document.write("<b>",times,"</b> 回目のご来訪ありがとう。</font><br>"); if (names=="匿名"||names=="お客"){ document.write("<div id='in_form' style='display:inline;'>"); document.write("<form name='f1'><font size=1 color=#ffbbbb>差し支えなければ、名前を教えて!</font><br>"); document.write("<input type='text' name='na' value='' onChange=putName()>"); document.write(" <input type='button' value='ok' onClick=putName()>"); document.write("</form></div>"); }else{ document.write("<div id='in_form' style='display:none;'><form name='f1'>"); document.write("<font size=1 color=#ffbbbb>差し支えなければ、名前を教えて!</font><br>"); document.write("<input type='text' name='na' value='",names,"' onChange=putName()>"); document.write(" <input type='button' value='ok' onClick=putName()>"); document.write("</form></div>"); document.write("<font size=1 color=#ffbbbb>"); document.write("(名前をクリックすると変更できます)</font>"); } } ///////////10分以内はカウントアップしない//////////// function todayTime(b){ today=new Date() d=(today.getTime())/(60*1000); d=Math.ceil(d); setCookie("todayTest",d); c=d-b; if(c>10||c<0){ times++; setCookie("TimesTest",times); } } </script> <!---------------ここまでは<HEAD>タグ内へ移してもよい----------------> <!---------------ここからは<BODY>タグ内に書くこと----------------> <script language="javascript"> names=getCookie("GuestName"); if(names==""){ names="お客"; setCookie("GuestName",names); } times=getCookie("TimesTest"); if(times==""){ times=0; } before=getCookie("todayTest"); if(before==""){ before=0; } todayTime(before); printName(); </script>

戻るJavaScriptメニューQPONホームページ