Here you will find an object with methods to save, read and erase cookies. Using these methods you can manipulate cookies on your site.
Cookies provide a means for a Web server to induce a client to store information about itself which can subsequently be called up by the Web server when required.
Source code for webtoolkit.cookies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/**
*
* Javascript cookies
* http://www.webtoolkit.info/
*
**/
function CookieHandler() {
this.setCookie = function (name, value, seconds) {
if (typeof(seconds) != 'undefined') {
var date = new Date();
date.setTime(date.getTime() + (seconds*1000));
var expires = "; expires=" + date.toGMTString();
}
else {
var expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
this.getCookie = function (name) {
name = name + "=";
var carray = document.cookie.split(';');
for(var i=0;i < carray.length;i++) {
var c = carray[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return null;
}
this.deleteCookie = function (name) {
this.setCookie(name, "", -1);
}
}
|