ASP. NET 3. Shopping Cart created by asp.net + cookie + javascrip

Source: Internet
Author: User
Tags set cookie

(1) first, introduce the basics of javascript cookie operations.


// Remove spaces and press ENTER
String. prototype. Trim = function ()
{
Return this. replace (/(^ \ s *) | (\ s * $)/g ,"");
}


// Set Cookie
Function setCookie (c_name, c_value, expiredays)
{
Var exdate = new Date ();
Exdate. setDate (exdate. getDate () + expiredays );

Document. cookie = c_name + "=" + escape (c_value) +
(Expiredays = null )? "": "; Expires =" + exdate. toGMTString ());
}

// Read the Cookie by name
Function getCookie (c_name)
{
If (document. cookie. length> 0)
{
Var m_car = document. cookie. split (';');
Var value =-1;
For (I = 0; I <m_car.length; I ++)
{
If (c_name.toString (). Trim () = (m_car [I]. split ('=') [0]). toString (). Trim ())
{
Value = (m_car [I]. split ('=') [1];
}

}
}
Return value;
}

 

 

From South-South Space

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.