How to expire a cookie in 30 minutes using jQuery?

后端 未结 3 774
灰色年华
灰色年华 2020-11-27 10:55

How to Expire a Cookie in 30 min ? I am using a jQuery cookie. I am able to do something like this.

$.cookie(\"example\", \"foo\", { expires: 1 });
         


        
3条回答
  •  盖世英雄少女心
    2020-11-27 11:25

    30 minutes is 30 * 60 * 1000 miliseconds. Add that to the current date to specify an expiration date 30 minutes in the future.

     var date = new Date();
     var minutes = 30;
     date.setTime(date.getTime() + (minutes * 60 * 1000));
     $.cookie("example", "foo", { expires: date });
    

提交回复
热议问题