Jquery cookie monitor

后端 未结 3 588
南方客
南方客 2020-12-15 11:02

What\'s the best JS or JQuery-specific approach to monitor a cookie through-out the page life on the browser and trigger an event, when the cookie is\' changed?

3条回答
  •  孤街浪徒
    2020-12-15 11:59

    There is a jQuery plugin for cookies.

    http://plugins.jquery.com/project/Cookie

    It is not difficult to access the cookies in a html document, they live in document.cookie.

    
    $.cookie('cookieName':'cookieValue');
    
    
    $.cookie('cookieName');
    
    
    $.cookie('cookieName', null);
    

    Additionally there are options arguments for add a cookie, e.g. expiry.

    However in reply to your question, I don't actually think you can apply a event listener on to cookies unfortunately.

提交回复
热议问题