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

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -