Home > Web Front-end > JS Tutorial > Examples of cookie usage in JavaScript

Examples of cookie usage in JavaScript

高洛峰
Release: 2016-11-26 14:16:02
Original
1062 people have browsed it

Recently, I was working on a project that involved writing some cookie examples. I found that I still have many shortcomings in js, but I need to work hard:






Untitled Document

<script><br> function cookie(name, value, options) {<br> if (typeof value ! = 'undefined') { // name and value given, set cookie<br>       options = options || {};<br>                                                                                                                                                           ​ <br>         var expires = '';<br>                                                                                                                                                                                             ) {<br>                 date = new Date();                                                                                       date = options.expires;<br>         }<br> expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE<br>         }<br>           var path = options.path ? '; path=' + options.path : '' ; Om var domain = options.Domain? '; Domain =' + options.dain: ''; <br> var secure = options.Secure? '; Secure': '; = ', encodeURIComponent(value), expires, path, domain, secure].join('');<br> } else { // only name given, get cookie<br>   var cookieValue = null;<br>     if (document.cookie && document.cookie != '') {<br>       var cookies = document.cookie.split(';');<br>                 for (var i = 0; i < cookies.length; i++) { <br>         var cookie = jQuery.trim(cookies[i]) ; O // DOES This Cookie String Begin with The name We Want? Ricomponent (cookie.substring ( name.length + 1));<br>  </p> <p>  $(document).ready(function(){<br>          if(cookie('show')==1)<br>            $(".introBuy").css("display", 'none');<br>       <br>       $("#close").click(function(){<br>           $(".introBuy").css("display", 'none');<br>           cookie('show',1)<br>            });<br>       <br>});<br></script>



关闭


Related labels:
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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template