javascript - JQuery and Cookie: How to remove them when user leaves the page or exit window/tab -
i learning use jquery cookie plugin @ https://github.com/carhartl/jquery-cookie
have read, it's easy read , remove cookie. question is: want cookie removed when user navigates away page or close window/tab, how do that? how detect such activity?
thanks.
$(window).on('beforeunload', function () { // remove cookie $.cookie("name_of_cookie", null); }); also, have 1 more option:
$(window).unload(function () { // remove cookie $.cookie("name_of_cookie", null); });
Comments
Post a Comment