javascript如何读取和写入数据到cookie [英] javascript how to read and write data to cookies

查看:94
本文介绍了javascript如何读取和写入数据到cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用javascript.thank来向cookie读取和写入数据.

How to read and write data to cookies by use javascript.thank you.

推荐答案

不知道
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


以下链接可能会帮助您:
JavaScript Cookies [ ^ ]
JavaScript和Cookies [
Following links might help you:
JavaScript Cookies[^]
JavaScript and Cookies[^]

All the best.
--Rajesh


像这样尝试:
try it like this:
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))
                    } 
          }
}//:


这篇关于javascript如何读取和写入数据到cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆