Home > Web Front-end > JS Tutorial > body text

Summary of jQuery implementation of forced cookie expiration methods

PHPz
Release: 2018-10-11 16:17:36
Original
1379 people have browsed it

This article is a detailed introduction to the solution to jquery forcing cookie invalidation. Friends who need it can come and refer to it. I hope it will be helpful to everyone

Method 1:

var date = new Date(); 
date.setTime(date.getTime() + (x * 60 * 1000)); 
$.cookie('example', 'foo', { expires: date });
Copy after login

Method two:

<script type="text/javascript">
var expiresDate= new Date();
expiresDate.setTime(expire.getTime() + (? * 60 * 1000)); //?替换成分钟数如果为60分钟则为 60 * 60 *1000
$.cookie("__cookie__", &#39;helloworld&#39;, {
      path : &#39;/&#39;,      //cookie的作用域
      expires : expiresDate
    });
}
</script>
Copy after login

Method three:

function SetCookie(name,value){
 var str=name+"="+escape(value);
 var dd = new Date(); 
 dd.setDate(dd.getDate()+1);//获取明天 
 var y = dd.getYear(); 
 var m = dd.getMonth()+1;//获取当前月份的日期
 var d = dd.getDate(); 
 date = new Date(y+&#39;-&#39;+m+&#39;-&#39;+d+&#39; 00:00:00&#39;);
 date.setTime(date.getTime());//明天的0:00:00
 str+=";expires="+date.toGMTString();
 document.cookie = str;
 }
Copy after login

The above is the summary of this article for everyone. I hope you will like it.

For more related tutorials, please visit JavaScript Video Tutorial

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!