简体   繁体   中英

Why isn't document.cookie getting set?

I have this JavaScript code that sets the document.cookie but when running it I can see document.cookie doesn't actually get set. See the screenshot below.

 (function() { 
      var offset = (new Date()).getTimezoneOffset()
      console.log("WAR");
      var date = new Date();console.log(offset);
      date.setTime(date.getTime()+3600000);
      var variable = "utc_offset="+offset+"; expires="+date.toGMTString();+"; path=/";
      console.log(variable); 
      document.cookie=variable;
})()

在此处输入图片说明

那是因为您不是在实际网页上,而是在新的 Chrome 标签上。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM