admin管理员组文章数量:1328037
I am learning to use this JQuery cookie plugin at
From what I have read, it's really easy to read and remove a cookie. My question is: I want the cookie to be removed when the user navigates away from the page or close the window/tab, how do I do that? How do I detect such activity?
Thanks.
I am learning to use this JQuery cookie plugin at
https://github./carhartl/jquery-cookie
From what I have read, it's really easy to read and remove a cookie. My question is: I want the cookie to be removed when the user navigates away from the page or close the window/tab, how do I do that? How do I detect such activity?
Thanks.
Share Improve this question edited Aug 10, 2015 at 11:45 Jaimin 8727 silver badges15 bronze badges asked Apr 18, 2013 at 18:52 neoneo 2,4719 gold badges44 silver badges67 bronze badges2 Answers
Reset to default 5$(window).on('beforeunload', function () {
// Remove the cookie
$.cookie("name_of_cookie", null);
});
Also, we have one more option:
$(window).unload(function () {
// Remove the cookie
$.cookie("name_of_cookie", null);
});
The update to the accepted answer would be:
Cookies.remove('name');
With: https://github./js-cookie/js-cookie
The jQuery plugin is not longer mantained.
版权声明:本文标题:javascript - JQuery and Cookie: How to remove them when user leaves the page or exit windowtab - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742241063a2438837.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论