Angular JS - IpCookies在localhost上无法正常工作

时间:2015-08-03 06:31:47

标签: javascript angularjs cookies

我现在使用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,因为我有这个应用程序的几个子域名。

1 个答案:

答案 0 :(得分:0)

希望这会有所帮助:

https://gitlab.isb-sib.ch/calipho/nextprot-search/commit/8d9e022f3648c5df3390389a0b2c50d53501239c?view=parallel

if ($window.location.hostname === "localhost") {
                    ipCookie('nxprofile', profile);
                    ipCookie('nxtoken', token);
               } else {
                    ipCookie('nxprofile', profile, { domain: '.nextprot.org' });
                    ipCookie('nxtoken', token, { domain: '.nextprot.org' });
               }