Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created December 20, 2012 01:20
Show Gist options
  • Select an option

  • Save chikoski/4342259 to your computer and use it in GitHub Desktop.

Select an option

Save chikoski/4342259 to your computer and use it in GitHub Desktop.
WebStorageを利用して、アクセス記録を残すプログラム
var storage = sessionStorage
var now = new Date();
var keyName = "2012f-11-1-3-lastvisited";
document.write("現在時刻は" + now + "です。<br>");
var lastvisited = storage.getItem(keyName);
document.write(buildMessage(lastvisited) + "<br>");
storage.setItem(keyName, now);
function buildMessage(d){
var msg = "初めての訪問です。";
if(d != null){
msg ="前の訪問は" + d + "です。";
}
return msg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment