Home  >  Article  >  Web Front-end  >  How to control cookie expiration time with jQuery_jquery

How to control cookie expiration time with jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:05:111252browse

The example in this article describes how jQuery controls cookie expiration time. Share it with everyone for your reference. The specific analysis is as follows:

The jquery.cookie() method can set cookies. By default, the browser will close the cookie and it will become invalid. Use the following method to solve this problem

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

Here we should pay attention to the capitalization of the methods quoted above: new Date() setTime() getTime() Many people on the Internet are very irresponsible and write new date(), etc. The results are not good, so please pay attention

I hope this article will be helpful to everyone’s jQuery programming.

Statement:
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