Cookie is a small text file sent by web server and saved by web browser on client machine.
There two type of cookies
Persistent cookies: cookies are stored on your
computer hard disk. They stay on your hard disk and can be accessed by
web servers until they are deleted or have expired.
Non-persistent cookies: cookies are saved only while
your web browser is running. They can be used by a web server only
until you close your browser. They are not saved on your disk.
Implement non-persistent cookie using java script
//Check session cookie
function bswayedcheckSessionCookie() {
var date = new Date();
var todayDate = date.getTime();
var cookieName = GetSessionCookie();
if (cookieName == "") {
var cookieName = "bSwayedSession" + todayDate;
cookieName = SetSessionCookie(cookieName);
}
return cookieName;
}
//Read session cookies
function GetSessionCookie() {
var name = "bSwayedSession";
var cookieArray = document.cookie.split(/[\;=\s]/);
for (var i = 0; i < cookieArray.length; i++) {
var cookieName = $jq191.trim(cookieArray[i]);
if (cookieName.indexOf(name) == 0) {
return cookieName;
}
}
return "";
}
//Set cookie
function SetSessionCookie(sessionCookieName) {
document.cookie = "BswayedSession" + "=" + sessionCookieName;
return document.cookie;
}
No comments:
Post a Comment