This example describes how JavaScript reads and writes cookies. Share to everyone for your reference. Specifically as follows:
There is no use to any JS library, directly using the JS method to read and write cookies
<HTML>
</HEAD>
<BODY>
<script language= "JavaScript" >
<!--
function Set_it () {
var the_text= "name=yourname&";
var toexpire= new Date ("March, 2008");
var expdate= "expires=" +toexpire.togmtstring ();
The_text+=expdate;
var newtext=escape (the_text);
Document.cookie=newtext;
}
function Read_it () {
if (document.cookie) {
var Mycookie=document.cookie;
var fixed_cookie= unescape (MyCookie);
var thepairs= fixed_cookie.split ("&");
var pair1= thepairs[0];
var pair2= thepairs[1];
var namevalue1= pair1.split ("=");
Alert ("read");
Alert ("Welcome," +namevalue1+ "!");
} else {
alert ("set");
Set_it ();
}
Read_it ();
-->
</SCRIPT>
</BODY>
</HTML>
I hope this article will help you with your JavaScript programming.