JavaScript Cookie Basics How to record user names-basics

Source: Internet
Author: User

The examples in this article describe the methods used by the JavaScript cookie base to record user names. Share to everyone for your reference, specific as follows:

There is a previous article on the basis of cookies, encapsulating the cookie.js, we use an example to apply this JS.

The most common is to remember the user name, when the user logged in once, through a cookie to record the user's account number and password, so the next time you open the page do not need to enter the account password again. Attached code:

<! DOCTYPE html>  

PS: Here again the previous section of the Cookie.js posted out to facilitate everyone to view:

function Setcookie (name,value,hours) {
 var d = new Date ();
 D.settime (D.gettime () + hours * 3600 * 1000);
 Document.cookie = name + ' = ' + value + '; Expires= ' + d.togmtstring ();
}
function GetCookie (name) {
 var arr = Document.cookie.split ('; ');
 for (var i = 0; i < arr.length i++) {
  var temp = arr[i].split (' = ');
  if (temp[0] = = name) {return
   temp[1];
  }
 }
 return ';
}
function Removecookie (name) {
 var d = new Date ();
 D.settime (D.gettime ()-10000);
 Document.cookie = name + ' = 1; Expires= ' + d.togmtstring ();
}

More readers interested in JavaScript-related content can view this site: "JavaScript in the JSON Operation tips Summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"

I hope this article will help you with JavaScript programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.