Set Get Delete Cookies
Question posted by: Inbaraj
(Member)
on
April 16th, 2007 06:08 AM
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
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
|
|
April 16th, 2007 10:58 AM
# 2
|
Re: Set Get Delete Cookies
What part do you not understand? Whatever page you saw must have contained some examples.
|
|
April 17th, 2007 04:59 AM
# 3
|
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 05:02 AM
# 4
|
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 11:20 AM
# 5
|
Re: Set Get Delete Cookies
Just set the expiry date in the past and the cookies will be deleted.
|
|
April 17th, 2007 11:21 AM
# 6
|
Re: Set Get Delete Cookies
I've merged the threads. They were on the same topic.
|
|
April 17th, 2007 11:24 AM
# 7
|
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 05:51 AM
# 8
|
Re: Set Get Delete Cookies
Here is the Cookies with example
Code: ( text )
<html> <head> <script type="text/javascript">
Code: ( text )
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) } } }
Code: ( text )
</script> </head> <body onLoad="checkCookie()"> </body> </html>
Last edited by acoder : November 3rd, 2007 at 08:33 AM.
Reason: Added code tags
|
|
November 3rd, 2007 05:52 AM
# 9
|
Re: Set Get Delete Cookies
Cookies full function
Code: ( text )
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 08:34 AM.
Reason: Added code tags
Not the answer you were looking for? Post your question . . .
183,909 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Latest Articles: Read & Comment
Top Javascript / DHTML / Ajax Forum Contributors
|