gpt4 book ai didi

javascript - JQuery 和 Cookie : How to remove them when user leaves the page or exit window/tab

转载 作者:搜寻专家 更新时间:2023-10-31 23:07:11 24 4
gpt4 key购买 nike

我正在学习使用这个 JQuery cookie 插件 https://github.com/carhartl/jquery-cookie

从我读到的内容来看,读取和删除 cookie 真的很容易。我的问题是:我希望在用户离开页面或关闭窗口/选项卡时删除 cookie,我该怎么做?我如何检测此类事件?

谢谢。

最佳答案

$(window).on('beforeunload', function () {
// Remove the cookie
$.cookie("name_of_cookie", null);
});

此外,我们还有一个选择:

$(window).unload(function () {
// Remove the cookie
$.cookie("name_of_cookie", null);
});

关于javascript - JQuery 和 Cookie : How to remove them when user leaves the page or exit window/tab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16090899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com