Set Get Delete Cookies 
April 16th, 2007, 07:08 AM
|  | Member | | Join Date: Apr 2007 Location: Puducherry <==> Coimbatore
Posts: 81
| | |
Hi...
I want to Set Get Delete Cookies using javascript i saw in net but i cant understand...
Plz help me with sample example.....
with reg
inba
| 
April 16th, 2007, 11:58 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,517
Provided Answers: 12 | | | re: Set Get Delete Cookies
What part do you not understand? Whatever page you saw must have contained some examples.
| 
April 17th, 2007, 05:59 AM
|  | Member | | Join Date: Apr 2007 Location: Puducherry <==> Coimbatore
Posts: 81
| | | re: Set Get Delete Cookies Quote: |
Originally Posted by acoder What part do you not understand? Whatever page you saw must have contained some examples. | I have Set the Cookies using
document.cookies=user.value+" "+pass.value;
I print the Cookies using
alert(document.cookies);
I dont know how to delete the cookies...
help me..
Reg
Inba
| 
April 17th, 2007, 06:02 AM
|  | Member | | Join Date: Apr 2007 Location: Puducherry <==> Coimbatore
Posts: 81
| | | re: Set Get Delete Cookies
Hi,,,
I have Create cookies using... javascript...
document.cookies=username.value+" "+pass.value;
To Display the cookies i used the codeing...
alert(document.cookies);
To delete the cookies i dont know... How to do this...
Help me out...
Is it right method to create a cookies.... If i am wrong plz correct me....
Thanks in advance..
With reg
Inbaraj....
| 
April 17th, 2007, 12:20 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,517
Provided Answers: 12 | | | re: Set Get Delete Cookies
Just set the expiry date in the past and the cookies will be deleted.
| 
April 17th, 2007, 12:21 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,517
Provided Answers: 12 | | | re: Set Get Delete Cookies
I've merged the threads. They were on the same topic.
| 
April 17th, 2007, 12:24 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,517
Provided Answers: 12 | | | re: Set Get Delete Cookies Quote: |
Originally Posted by Inbaraj Hi,,,
I have Create cookies using... javascript...
document.cookies=username.value+" "+pass.value;
...
Is it right method to create a cookies.... If i am wrong plz correct me....
Thanks in advance..
With reg
Inbaraj.... | To create cookies, you need to set an expiry date too, e.g. 1 day, 1 week.
See these two links: http://www.quirksmode.org/js/cookies.html http://www.w3schools.com/js/js_cookies.asp | 
November 3rd, 2007, 06:51 AM
| | Newbie | | Join Date: Jul 2007
Posts: 2
| | | re: Set Get Delete Cookies
Here is the Cookies with example - <html>
-
<head>
-
<script type="text/javascript">
- function getCookie(c_name)
-
{
-
if (document.cookie.length>0)
-
{
-
c_start=document.cookie.indexOf(c_name + "=")
-
if (c_start!=-1)
-
{
-
c_start=c_start + c_name.length+1
-
c_end=document.cookie.indexOf(";",c_start)
-
if (c_end==-1) c_end=document.cookie.length
-
return unescape(document.cookie.substring(c_start,c_end))
-
}
-
}
-
return ""
-
}
-
-
function setCookie(c_name,value,expiredays)
-
{
-
var exdate=new Date()
-
exdate.setDate(exdate.getDate()+expiredays)
-
document.cookie=c_name+ "=" +escape(value)+
-
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
-
}
-
-
function checkCookie()
-
{
-
username=getCookie('username')
-
if (username!=null && username!="")
-
{alert('Welcome again '+username+'!')}
-
else
-
{
-
username=prompt('Please enter your name:',"")
-
if (username!=null && username!="")
-
{
-
setCookie('username',username,365)
-
}
-
}
-
}
- </script>
-
</head>
-
-
<body onLoad="checkCookie()">
-
</body>
-
</html>
Last edited by acoder; November 3rd, 2007 at 09:33 AM.
Reason: Added code tags
| 
November 3rd, 2007, 06:52 AM
| | Newbie | | Join Date: Jul 2007
Posts: 2
| | | re: Set Get Delete Cookies
Cookies full function - function createCookie(name,value,days) {
-
if (days) {
-
var date = new Date();
-
date.setTime(date.getTime()+(days*24*60*60*1000));
-
var expires = "; expires="+date.toGMTString();
-
}
-
else var expires = "";
-
document.cookie = name+"="+value+expires+"; path=/";
-
}
-
-
function readCookie(name) {
-
var nameEQ = name + "=";
-
var ca = document.cookie.split(';');
-
for(var i=0;i < ca.length;i++) {
-
var c = ca[i];
-
while (c.charAt(0)==' ') c = c.substring(1,c.length);
-
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
-
}
-
return null;
-
}
-
-
function eraseCookie(name) {
-
createCookie(name,"",-1);
-
}
Last edited by acoder; November 3rd, 2007 at 09:34 AM.
Reason: Added code tags
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|