我现在使用ivpusic / angular-cookie包为我的本地应用程序。我可以像这样设置一个简单的cookie:
ipCookie('force-premium', true, { expires: 1, path: '/' });
但是,每当我输入一个不同于null的域名时,这都不会起作用。例如,这不会为我创建一个cookie
ipCookie('force-premium', true, { expires: 1, path: '/', domain: 'localhost' });
但不知何故,这是有效的
ipCookie('force-premium', true, { expires: 1, path: '/', domain: '' });
此代码有什么问题?我需要设置域名,因为我想创建一个域范围的cookie,因为我有这个应用程序的几个子域名。
答案 0 :(得分:0)
希望这会有所帮助:
if ($window.location.hostname === "localhost") {
ipCookie('nxprofile', profile);
ipCookie('nxtoken', token);
} else {
ipCookie('nxprofile', profile, { domain: '.nextprot.org' });
ipCookie('nxtoken', token, { domain: '.nextprot.org' });
}