###前提・実現したいこと
JavaScriptで訪問回数を数えたいのですがサイトのサンプルを実行しても回数がカウントされません。
###該当のソースコード
HTML
1<html> 2<head> 3<title>訪問回数を表示する</title> 4<meta charset="utf-8"/> 5</head> 6<body> 7<script language="JavaScript"> 8function setCount(n) 9{ 10 theDay = 30; 11 setDay = new Date(); 12 setDay.setTime(setDay.getTime()+(theDay*1000*60*60*24)); 13 expDay = setDay.toGMTString(); 14 document.cookie = "count="+n+";expires="+expDay; 15} 16function getCount() 17{ 18 theName = "count="; 19 theCookie = document.cookie+";" 20 start = theCookie.indexOf(theName); 21 if (start != -1) 22 { 23 end = theCookie.indexOf(";",start); 24 count = eval(unescape(theCookie.substring(start+theName.length,end))); 25 document.write(count+"回目のアクセスです"); 26 setCount(count+1); 27 }else{ 28 document.write("初めてのアクセスですね"); 29 setCount(2); 30 } 31} 32getCount(); 33</script> 34</body> 35</html>
###試したこと
2つか3つほどのサイトを巡って別々のサンプルを実行してみたのですが、どのサンプルでも回数はカウントされませんでした。
ブラウザのアドレスバーに file:/// と表示されていませんか
回答2件
あなたの回答
tips
プレビュー