JavaScript saves login information in cookies

Source: Internet
Author: User
Tags date return setcookie

<script language=javascript>
function Setcookies (name,value)
{
var days = 30; This cookie will be saved for 30 days
var exp = new Date (); New Date ("December 31, 9998");
Exp.settime (Exp.gettime () + days*24*60*60*1000);
Document.cookie = name + "=" + Escape (value) + "expire*=" + **p.togmtstring ();
}

function GetCookies (name)
{
var arr = Document.cookie.match (New RegExp ("(^)" +name+ "= ([^;] *)(;$)"));
if (arr!= null) return unescape (arr[2)); return null;
}

function GetCookies ()
{

Document.form1.username.value=getcookies ("Loginusername");
\ Put the form you want to initialize here
}

function Delcookies (name)
{
var exp = new Date ();
Exp.settime (Exp.gettime ()-1);
var cval=getcookie (name);
if (cval!=null) document.cookie=name + "=" +cval+ "; expire*=" +**p.togmtstring ();
}

function Submit ()
{
Username=document.form1.username.value;
Setcookies (' Loginusername ', username)
\ Create a cookie, the first name, followed by the value
}
</script>
<body onload= "getcookies ()" >
</body>

<script type= "Text/javascript" src= "123.js" ></script>
<script type= "Text/javascript" >
function foo ()
{
var name = document.getElementById ("name"). Value;
if (name)
{
Setcookie ("name", name);
}
document.getElementById ("Show"). innerhtml+= ("Newest Name:" + GetCookie ("name") + "<br>");

}
</script>
<br>
<input type= "text" id= "name" size= "/>"
<input type= "button" value= "Setcookie" onclick= "foo ()"/>
<div id= "Show" ></div>
Sample source Code
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>js Operation Cookie Easy Network Technology Service Center Http://www.escdns.com%3c/title>

<body>
<input type= "button" name= "button" id= "button" value= "Remove Cookies" onclick= "Window.cookie.remove ()"/>
<script language= "javascript" type= "Text/javascript" >
function Cookie () {
var self = this;
var trim = function (str) {
Return Str.replace (/(^s*) (s*$)/g, "");
}
var init = function () {

Related Article

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.