473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Set Get Delete Cookies

Inbaraj
76
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
Apr 16 '07 #1
8 16154
acoder
16,027 Expert Mod 8TB
What part do you not understand? Whatever page you saw must have contained some examples.
Apr 16 '07 #2
Inbaraj
76
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
Apr 17 '07 #3
Inbaraj
76
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....
Apr 17 '07 #4
acoder
16,027 Expert Mod 8TB
Just set the expiry date in the past and the cookies will be deleted.
Apr 17 '07 #5
acoder
16,027 Expert Mod 8TB
I've merged the threads. They were on the same topic.
Apr 17 '07 #6
acoder
16,027 Expert Mod 8TB
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
Apr 17 '07 #7
sumodh
2
Here is the Cookies with example

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
Expand|Select|Wrap|Line Numbers
  1. function getCookie(c_name)
  2. {
  3. if (document.cookie.length>0)
  4.   {
  5.   c_start=document.cookie.indexOf(c_name + "=")
  6.   if (c_start!=-1)
  7.     { 
  8.     c_start=c_start + c_name.length+1 
  9.     c_end=document.cookie.indexOf(";",c_start)
  10.     if (c_end==-1) c_end=document.cookie.length
  11.     return unescape(document.cookie.substring(c_start,c_end))
  12.     } 
  13.   }
  14. return ""
  15. }
  16.  
  17. function setCookie(c_name,value,expiredays)
  18. {
  19. var exdate=new Date()
  20. exdate.setDate(exdate.getDate()+expiredays)
  21. document.cookie=c_name+ "=" +escape(value)+
  22. ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
  23. }
  24.  
  25. function checkCookie()
  26. {
  27. username=getCookie('username')
  28. if (username!=null && username!="")
  29.   {alert('Welcome again '+username+'!')}
  30. else 
  31.   {
  32.   username=prompt('Please enter your name:',"")
  33.   if (username!=null && username!="")
  34.     {
  35.     setCookie('username',username,365)
  36.     }
  37.   }
  38. }
Expand|Select|Wrap|Line Numbers
  1. </script>
  2. </head>
  3.  
  4. <body onLoad="checkCookie()">
  5. </body>
  6. </html>
Nov 3 '07 #8
sumodh
2
Cookies full function

Expand|Select|Wrap|Line Numbers
  1. function createCookie(name,value,days) {
  2.     if (days) {
  3.         var date = new Date();
  4.         date.setTime(date.getTime()+(days*24*60*60*1000));
  5.         var expires = "; expires="+date.toGMTString();
  6.     }
  7.     else var expires = "";
  8.     document.cookie = name+"="+value+expires+"; path=/";
  9. }
  10.  
  11. function readCookie(name) {
  12.     var nameEQ = name + "=";
  13.     var ca = document.cookie.split(';');
  14.     for(var i=0;i < ca.length;i++) {
  15.         var c = ca[i];
  16.         while (c.charAt(0)==' ') c = c.substring(1,c.length);
  17.         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  18.     }
  19.     return null;
  20. }
  21.  
  22. function eraseCookie(name) {
  23.     createCookie(name,"",-1);
  24. }
Nov 3 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Phil Powell | last post by:
I am having this problem: My PHP script will set a cookie, it's there in my /Cookies folder. I delete the cookie (I have to for testing purposes, the PHP script I run behaves according to this...
2
by: Dan | last post by:
I persist the login info using cookies so that a user doesn't have to login every time they come to our website, unless they previously logged out. Everything works OK on W98 SE, and Windows XP Pro...
3
by: Warp | last post by:
If I have a cookie with 'key/value' pairs, how would I delete a specific 'key/value' pair while preserving the remaining pairs? I tried to do something like: cookie(key)="" but it didn't seem to...
2
by: phoenix | last post by:
Hello, I tried the following to delete the cookies Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Cookies ), true); but always get the message that "index.dat" is...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
0
by: Bill Borg | last post by:
Hello all, Not sure I can describe this adequately, but I am creating an endless loop when an authenticated user signs out. When the user signs out, I want to remove authentication, abandon...
5
by: ad | last post by:
Hi, How can I delete the cookie in client?
3
by: kendera | last post by:
Is it possible to programmatically delete cookies? Can anyone help me with this...
4
by: itrahulsoni | last post by:
hi all, I want to delete the cookies that are set by the google personalize home page or when once i view the you tube video cookie is set I want it to delete programmatically so I am able to see...
2
Inbaraj
by: Inbaraj | last post by:
Hi I have create a cookie as document.cookie=text1.value+" "+text2.value; I am able to retrive the cookies... But i am not able to delete the cookies... Plz help me in deleting the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.