may88seiji
6/20/2017 - 7:46 AM

cookie http://www.pori2.net/js/cookie/2.html

  var cook;
  var cStart,cEnd;
  var cnt;
  var date1,date2; //日付データを格納する変数
  var kigen = 30; //cookieの期限

  date1 = new Date();//現在の日付データを取得
  date1.setTime(date1.getTime() + kigen * 24 * 60 * 60 * 1000); //30日後の日付データを作成
  date2 = date1.toGMTString(); //GMT形式に変換して変数date2に格納する

  if (navigator.cookieEnabled){
    cook = document.cookie + ";";
    cStart = cook.indexOf("counts=",0);
    if (cStart == -1){//初回
      document.cookie = "counts=1;expires=" + date2;
      pcIntroduction.init();
    } else {//2回目以降
      cEnd = cook.indexOf(";",cStart);
      cnt = cook.substring(cStart+7,cEnd);
      console.log("二回目以降");
      try {
        cnt = parseInt(cnt)+1;
        document.cookie = "counts=" + cnt + ";expires=" + date2;
      } catch(e) {
      }
    }
  } else {
  }