Various actions of cookies in JS

Source: Internet
Author: User
Tags setcookie

<script>
/* If there is no cookie information, the div is displayed, otherwise it is not displayed. (please test in Firefox) */
Set cookies
function Setcookie (name, value, Iday) {
var odate=new Date ();
Odate.setdate (Odate.getdate () +iday);
document.cookie=name+ ' = ' +value+ '; expires= ' +odate;
}

Read cookies
function GetCookie (name)
{
var arr=document.cookie.split (';'); Define an array
var re=new RegExp (' \\b ' +name+ ' =\\w+ '); Define a regular
var res=document.cookie.match (re); Match the selected field
if (res) {
return res[0].split (' = ') [1]; If the match succeeds, the result is returned
}
Else
{
Return '; Otherwise, return null
}
}

Delete Cookies
function Removecookie (name) {Setcookie (name, ' 1 ',-1)}//Use the Setcookie function to set the time to 1 to achieve the delete effect (no method is removed by default)

Window.onload=function ()
{
var Odiv=document.getelementbyid (' Div1 ');

if (!getcookie (' arrial '))
{
odiv.style.display= ' block ';
Setcookie (' arrial ', ' 1 ', 30); Add ' arrial ' to the cookie, ' 1 ', 30
}
};
</script>file:///home/hezhenzhen/.cache/.fr-zzlgid/%c3%90%c3%82%c3%8a%c3%96%c2%b5%c2%bc%c2%ba%c2%bd%c2% Bf%c3%8e%c2%b3%c3%8c%c3%94%c2%b4%c2%b4%c3%ba%c3%82%c3%ab/index.html

Various actions of cookies in JS

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.