javascript - Cookie 有效期设置为几分钟而不是几天
问题描述
我正在使用一个免费的 Wordpress 插件,不幸的是作者似乎不是很主动,尽管它是一个超级有用且很棒的插件。
所以我遇到了一个问题,就像在插件的配置中一样,它允许您以天为单位设置 cookie 的到期时间,但我想知道是否可以修改代码并将其设置为几分钟或几秒钟.
所以我进入插件文件,发现我认为是设置 cookie 的实际代码(对不起,但我不是程序员,所以我不能真正说出这段代码的作用)所以我想知道是否有人可以向我确认这是否是控制 cookie 过期的实际代码,以及是否可以对其进行更改以完成我需要的操作。
这是代码:
!function(e){var n=!1;if("function"==typeof define&&define.amd&&(define(e),n=!0),"object"==typeof exports&&(module.exports=e(),n=!0),!n){var o=window.Cookies,t=window.Cookies=e();t.noConflict=function(){return window.Cookies=o,t}}}(function(){function e(){for(var e=0,n={};e<arguments.length;e++){var o=arguments[e];for(var t in o)n[t]=o[t]}return n}function n(o){function t(n,r,i){var c;if("undefined"!=typeof document){if(arguments.length>1){if(i=e({path:"/"},t.defaults,i),"number"==typeof i.expires){var a=new Date;a.setMilliseconds(a.getMilliseconds()+864e5*i.expires),i.expires=a}i.expires=i.expires?i.expires.toUTCString():"";try{c=JSON.stringify(r),/^[\{\[]/.test(c)&&(r=c)}catch(f){}r=o.write?o.write(r,n):encodeURIComponent(String(r)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),n=encodeURIComponent(String(n)),n=n.replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent),n=n.replace(/[\(\)]/g,escape);var s="";for(var p in i)i[p]&&(s+="; "+p,i[p]!==!0&&(s+="="+i[p]));return document.cookie=n+"="+r+s}n||(c={});for(var d=document.cookie?document.cookie.split("; "):[],u=/(%[0-9A-Z]{2})+/g,l=0;l<d.length;l++){var C=d[l].split("="),g=C.slice(1).join("=");'"'===g.charAt(0)&&(g=g.slice(1,-1));try{var m=C[0].replace(u,decodeURIComponent);if(g=o.read?o.read(g,m):o(g,m)||g.replace(u,decodeURIComponent),this.json)try{g=JSON.parse(g)}catch(f){}if(n===m){c=g;break}n||(c[m]=g)}catch(f){}}return c}}return t.set=t,t.get=function(e){return t.call(t,e)},t.getJSON=function(){return t.apply({json:!0},[].slice.call(arguments))},t.defaults={},t.remove=function(n,o){t(n,"",e(o,{expires:-1}))},t.withConverter=n,t}return n(function(){})});
提前致谢
解决方案
我今天再试一次,正如 charlietfl 所说,如果你使用小数,它会起作用。我的错误是我尝试使用 , (coma) 而不是 . (点)。
谢谢
推荐阅读
- php - 我想更新 Transactions 表中的记录并将其发布到 Approved 表,同时将 Transaction 批准的状态从 0 更新为 1
- tensorflow - 在具有多个显卡(例如 K80)的 NVIDIA GPU 上,为什么 torch.cuda.device_count() 返回 1?
- javascript - UI5 自定义中间件在通过 Karma 测试套件访问时通常无法解析 JSON 主体
- c# - 在 Blazor 服务器中使用 NavigationManager NavigateTo 强制加载不会重新加载整个索引
- json - 为什么 tableview 没有在 swift 中重新加载 JSON 数据
- arrays - 如果条件,将数字从 json 更改为文本
- r - 从 ggstatsplot 增加 ggbetweenstats 的 inplot 均值的字体大小
- react-native - 错误:未知命名模块:“./constants”
- sql - 使用 SQL 查找客户订购产品的总次数
- c# - 如何在同一单元测试中最小起订量,来自同一配置的两个值