admin管理员组文章数量:1313163
i'm trying to create a cookie with greasemonkey in order to stop a window from popping up (after the windows pops up a cookie is created the the window won't popup to many times... this is the code
function setCookie(c_name, value, expiredays) {
var exdate = new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ?
"" :
";expires="+exdate.toUTCString());
}
var cookie_names = [
'showDrushimPopUnderUserClick',
'showDrushimPopUnder308'
];
for (var i in cookie_names) {
setCookie(cookie_names[i], 1, 0);
}
but no cookie is been created....
i'm trying to create a cookie with greasemonkey in order to stop a window from popping up (after the windows pops up a cookie is created the the window won't popup to many times... this is the code
function setCookie(c_name, value, expiredays) {
var exdate = new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ?
"" :
";expires="+exdate.toUTCString());
}
var cookie_names = [
'showDrushimPopUnderUserClick',
'showDrushimPopUnder308'
];
for (var i in cookie_names) {
setCookie(cookie_names[i], 1, 0);
}
but no cookie is been created....
Share Improve this question edited Oct 28, 2014 at 1:01 Mr. Polywhirl 48.8k12 gold badges93 silver badges144 bronze badges asked Nov 19, 2012 at 11:14 rafi wienerrafi wiener 6071 gold badge12 silver badges19 bronze badges1 Answer
Reset to default 6If you set a cookie that has an expires
value equal to, or older than, the current system clock, it actually deletes the named cookie instead (Unless the path
or domain
are different, or it is a "secure" cookie -- none of which apply here).
This:
setCookie(cookie_names[i], 1, 0);
Causes that function to set a cookie with an instant expiration value, effectively deleting any cookie with that name.
To actually set a new cookie, use:
setCookie(cookie_names[i], 1, null);
which will cause your code to set a session cookie -- which is probably what you want.
Or use:
setCookie(cookie_names[i], 1, 1);
To set a cookie that expires in a day.
本文标签: create a cookie with javascript in greasemonkeyStack Overflow
版权声明:本文标题:create a cookie with javascript in greasemonkey - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741924220a2405187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论