如果url有特定的术语,比如/abc-def/usingjQuery,我必须删除特定的Cookie

I have to delete the particular Cookie if the url has specific term like /abc-def/ using jQuery.

本文关键字:Cookie 删除 usingjQuery 比如 url 术语 如果 abc-def      更新时间:2023-09-26

如果url有特定的术语,比如/abc def/使用jQuery,我必须删除特定的Cookie。

我怎样才能做到这一点?

您也可以在纯javascript中执行类似操作:

var deleteCookie = function(name,urlValue) {
 if(window.location.href.indexOf(urlValue) > -1{
    document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
 }
};

然后只调用deleteCookie("test", "/abc-def/");

要通过jQuery删除cookie,请使用$.removeCookie('cookie_name', { path: '/' });

在您的情况下,请尝试:

$.removeCookie('cookie_name', { path: '/abc-def/' });