问题标签 [js-cookie]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1820 浏览

jquery - jQuery - 从选择菜单中设置和检索 cookie

我有一个选择菜单,可让您选择首选的送货国家/地区。当您选择一个选项时,它会在下方显示相关国家/地区。

我正在尝试使用js-cookie设置一个 cookie ,以便始终为用户记住最后一次选择。这是我到目前为止所拥有的,但它不起作用:

https://jsfiddle.net/33xfzvg8/11/

我想将选择选项的值存储为 cookie,然后使用相同的值来显示各自的国家信息。这是当前存储的 cookie,看起来不正确:

{%220%22:{%22jQuery112405649891521717818%22:9}%2C%22length%22:1%2C%22context%22:{%22location%22:{%22href%22:%22https://zed-labz.myshopify.com/pages/delivery%22%2C%22ancestorOrigins%22:{}%2C%22origin%22:%22https://zed-labz.myshopify.com%22%2C%22protocol%22:%22https:%22%2C%22host%22:%22zed-labz.myshopify.com%22%2C%22hostname%22:%22zed-labz.myshopify.com%22%2C%22port%22:%22%22%2C%22pathname%22:%22/pages/delivery%22%2C%22search%22:%22%22%2C%22hash%22:%22%22}%2C%22mc-embedded-subscribe-form%22:{%220%22:{}%2C%221%22:{}}}%2C%22selector%22:%22#deliverycountry1%22}

0 投票
1 回答
1405 浏览

javascript - 未捕获的类型错误:无法读取属性“cookie”

所以,我有一个页面,我用 js-cookie 脚本和以下代码设置了一个 cookie。js.cookie-2.1 在该脚本之前加载。

那里没有JS错误。当我尝试在不同的页面上获取 cookie 值时,看起来 cookie 脚本没有加载。使用以下代码

而且我收到此错误“未捕获的类型错误:无法读取未定义的属性'cookie'”。js-cookie 脚本也在上述代码之前加载。

0 投票
3 回答
22347 浏览

javascript - 独立 js-cookie javascript 库中的“未定义 Cookie”?

我不是 javascript 大师,但尝试使用 js-cookie。我包含了脚本:https ://github.com/js-cookie/js-cookie :我下载了它(链接),并将它放在我自己的服务器上的 js 文件中。然后我将它包含在一个测试文件中并读取了一些 cookie,但它一直在浏览器控制台中向我显示错误“未定义 cookie”。我在做什么错:(?代码:

0 投票
0 回答
116 浏览

javascript - JS Cookie 候选清单 - 单击时添加/删除 ID

我正在建立一个假日公寓网站,并希望有一个入围/收藏功能。Cookie 可以用于此目的,因为没有用户登录。

单击公寓页面上的“添加到候选名单”会将房产的 ID(例如 200)添加到保存在 cookie 中的数组中。再次单击它会删除 ID。然后我可以在我的 WordPress 循环中使用这个数组在候选列表页面上显示相关属性。

因此,例如,如果用户将 4 套公寓列入候选名单,则 cookie 将是公寓 ID 列表:200、17、34、99

我在网站的其他地方使用 js-cookie ( https://github.com/js-cookie/js-cookie ),但这个候选名单功能对我来说太先进了。

谢谢您的帮助。

干杯,克莱

0 投票
1 回答
1207 浏览

javascript - 将 cookie 设置为域

嗨,我正在研究 React,a,使用 js-cookie 库来管理 cookie。现在我正在创建一个 cookie:

我的应用程序在子域中运行:subdomain.domain.com 我需要将此 cookie 设置为.domain我的意思是,对于属于同一域的所有站点,在创建 cookie 时如何指定?

另外,是否可以以通用方式制作它?我的意思是,如果我更改域,我不必更改应用程序的代码。

谢谢

0 投票
1 回答
89 浏览

javascript - 将 cookie 应用于s 与 js-cookie

我希望将 cookie 应用于两个输入的默认值。我正在使用 GitHub 的 jscookie,最好也使用 jscookie 来获得答案。我有一个默认值为零的输入,我希望它在第一次回答后默认为他们存储的 cookie。例如

带有 jscookie 插件的 JavaScript/JQuery:

因此,在重新加载页面后,我希望该值是最初输入的值。cookie 已保存,但并未应用于输入。我已经尝试了几乎所有我能想到的语法变化,没有任何帮助。提前感谢您的回复!

0 投票
4 回答
5796 浏览

wordpress - Woocommerce - Cookies is not defined

Well,

I'm getting JS error "Cookies is not defined", but "js.cookie.min.js" is loaded before "woocommerce.min.js".

I check apache log to see if there's any error, but has none. I don't have caching plugins.

I don't know how to track this error to find the root cause, everything seems OK.

enter image description here

waitForImages is another JS that is loaded but I'm getting a error.

Am I missing something? Tips to find the bug?

EDIT*********

Further investigation

This is the code from js-cookie, for some reason I don't understand js-cookie is setting "registeredInModuleLoader" to true, but the variable "Cookies" is not defined yet.

EDIT 2

I think I found the issue, but don't know why yet.

Monday I put a singup form from MailChimp which needs this code. I think that the problem is with "embed.js", because in the condition "define.amd" (above) points to "embed.js". After remove this script the error is gone.

Any thoughts?

SOLVED

I change the position of Mailchimp script to the last item before , no more issues.

Thanks.

0 投票
0 回答
40 浏览

jquery - jQuery cookie 加倍值

每次,添加到进度条函数运行时,它都会使 cookie 的值加倍,每次 5 秒倒计时计时器结束时,它应该加 10。

任何人都可以帮助指出为什么它在添加后设置时会加倍 cookie 值。

0 投票
1 回答
6057 浏览

javascript - 在 React 中使用 js-cookie 在域级别设置 cookie

我有一个反应应用程序。目前我正在使用js-cookie来管理我的 cookie。现在我面临这个问题:我需要 cookie 在域级别而不是子域级别可用。

例如:我的站点在 mysite.mydomain.com 下运行,那么我需要 cookie 可用于在 .mydomain 下运行的任何站点

我在其他帖子中读到,只需将路径设置为“/”就可以实现。所以我很生气:

但是它仍在创建 cookiemysite.mydomain.com

那么,我还能做什么?我不想在创建 cookie 时直接写入域,因为它不干净,而且开发是在 localhost 下,它会变得一团糟。所以,我正在寻找一个干净的解决方案

非常感谢

0 投票
1 回答
6366 浏览

node.js - 如何在 TypeScript 项目中使用 js-cookie?

我想在我的 TypeScript 项目中使用js-cookie库。

npm install js-cookie @types/js-cookie --save-dev首先,我通过在包含node_modules和的目录中运行来安装库和类型package.jsonpackage.json现在包含并且."@types/js-cookie": "^2.1.0"中有一个文件夹js-cookienode_modules

然后我加了

到我的 TypeScript 文件。WebStorm 没有显示任何错误。

当我运行服务器时,我收到以下错误:

我在导入时到底做错了什么,我js-cookie该如何解决?