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

How to control cookie expiration time with jQuery_jquery

WBOY
Release: 2016-05-16 16:05:11
Original
1287 people have browsed it

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>
Copy after login

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.

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