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

Examples of cookie usage in JavaScript

高洛峰
高洛峰Original
2016-11-26 14:16:021035browse

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>



关闭


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