我完全搞不懂这段代码有什么问题,
第一次迭代完美运行:
if (window.location.href != "http://fiddlehead.co/pages/verify-age") {
current_url = window.location;
document.cookie = 'landing_Cookie=' + escape(current_url) +';'
};
但我需要 cookie 在几秒钟内过期,但这是行不通的(没有创建 cookie):
if (window.location.href != "http://fiddlehead.co/pages/verify-age") {
function createCookie(name, value) {
var date = new Date();
date.setTime(date.getTime()+(30*1000));
var expires = "; expires="+date.toGMTString();
var current_url = window.location;
document.cookie = name+"="+escape(value)+expires+"; path=/";
};
createCookie('landing_Cookie', current_url);
};
任何帮助将不胜感激,这是我用头撞 table 几个小时的最后一道障碍!
最佳答案
var current_url = window.location;
必须放在 createCookie
的正文之外。
关于javascript - 创建 cookie 将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15183638/