Connecting Tech Pros Worldwide Forums | Help | Site Map

save cookie and retrieve in javascript

Member
 
Join Date: Jan 2009
Posts: 52
#1: Jun 25 '09
hi
i want to set cookie with javascript
i use this code
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. document.cookie="username='ali'";
  3.  
  4. </script>
with using this code when i look at previous cookie that stored in my computer
i dont this cookie
how do save cookie and retrieve with javasript?
thanks alot for your help

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Jun 26 '09

re: save cookie and retrieve in javascript


To deal with cookies easily, you need three functions: to save, read and delete. Here are two links which should help:
http://www.quirksmode.org/js/cookies.html
http://www.w3schools.com/JS/js_cookies.asp

PS: use the script type attribute, not the deprecated language attribute:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
Reply