function addCookie(name, value, expiresHours) {
    var cookieString = name + "=" + escape(value);
    //判断是否设置过期时间,0代表关闭浏览器时失效
    if (expiresHours > 0) {
        var date = new Date();
        date.setTime(date.getTime() + expiresHours * 1000);
        cookieString = cookieString + ";expires=" + date.toGMTString() + ";path=" + window.location.pathname;
    console.log(cookieString);
    }
    document.cookie = cookieString;
}
";path=" + window.location.pathname;
多个网页设置相同的cookie时候不会覆盖,英文在不同的路径下。

相关文章:

  • 2021-12-29
  • 2022-01-20
  • 2022-01-18
  • 2021-08-22
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2022-01-26
  • 2021-09-22
  • 2021-07-25
  • 2021-09-26
  • 2022-01-14
  • 2021-11-30
相关资源
相似解决方案