milkcat
-
Total Posts
:
4
- Scores: 0
-
Reward points
:
0
- Joined: 10/2/2001
- Location:
-
Status: offline
|
Help! How to create a cookie by javascript???
Wednesday, October 03, 2001 8:06 AM
( permalink)
Original message moved by TNO Reason :
Hi.. i am trying to create a cookie for the username..so everytime the user go into the site from same browser no need to type in their username, only the password.
|
|
|
|
imav8n
-
Total Posts
:
95
- Scores: 0
-
Reward points
:
0
- Joined: 7/3/2001
- Location: USA
-
Status: offline
|
Re: Help! How to create a cookie by javascript???
Wednesday, October 03, 2001 4:01 PM
( permalink)
|
|
|
|
TNO
-
Total Posts
:
2094
- Scores: 36
-
Reward points
:
0
- Joined: 12/18/2004
- Location: Earth
-
Status: offline
|
RE: Re: Help! How to create a cookie by javascript???
Wednesday, March 19, 2008 11:11 AM
( permalink)
Put this in a separate library, or at the top of your page. Here is the API: Cookie.getCookie(name) Cookie.deleteCookie(name,path,domain) Cookie.setCookie(ame,value,expires,path,domain,secure)
var Cookie = (function (){
return {
getCookie : function(name){
var start = document.cookie.indexOf(name + "=");
var len = start + name.length + 1;
if ((!start) && (name !== document.cookie.substring(0, name.length))){
return null;
}
if (start === -1) {
return null;
}
var end = document.cookie.indexOf(';', len);
if (end === -1) {
end = document.cookie.length;
}
return unescape(document.cookie.substring(len, end));
},
deleteCookie : function (name,path,domain) {
if (Cookie.getCookie(name)) {
document.cookie = name + '=' + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
},
setCookie : function(name,value,expires,path,domain,secure){
var today = new Date();
if(expires){
expires = expires*1000*60*60*24;
}
var expires_date = new Date(today.getTime() + (expires));
name = name;
value = escape(value);
expires = ((expires) ? ";expires=" + expires_date.toGMTString() : "");
path = ((path) ? ";path=" + path : "");
domain = ((domain) ? ";domain=" + domain : "");
secure = ((secure) ? ";secure" : "");
today.setTime(today.getTime());
document.cookie = name + "=" + value + expires + path + domain + secure;
}
}
})();
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
|
|