Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to read and write data to cookies by use javascript.thank you.
Posted
Updated 29-Aug-12 1:43am
v2

Don't you know about google[^]? Your subject itself is giving About 4,510,000 results (0.28 seconds). Google is your friend. Try using that first. If any problem comes then you can ask for the solution. We all are here to guide you, help you.


All the best.
--Amit
 
Share this answer
 
Following links might help you:
JavaScript Cookies[^]
JavaScript and Cookies[^]

All the best.
--Rajesh
 
Share this answer
 
hi, try it like this:
JavaScript
function setCookie(name,value)
{
    var Days = 30;
    var exp = new Date(); 
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function getCookie(Name) {
    var search = "[" + Name + "]="
          if (document.cookie.length > 0) { // if there are any cookies
                    offset = document.cookie.indexOf(search) 
                    if (offset != -1) { // if cookie exists 
                              offset += search.length 
                              // set index of beginning of value
                              end = document.cookie.indexOf(";", offset) 
                              // set index of end of cookie value
                              if (end == -1) 
                                        end = document.cookie.length
                              return unescape(document.cookie.substring(offset, end))
                    } 
          }
}//:$
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900