M
Mike
I got the code below from an earlier post but I can't get it to work
(I get an error on the "for (i=0; i<a.length; i++)" line) Anyone have
code that works for cookies with keys?
Using the code provided below, examine
getCookie("APP","GROUPNUMBER")
and
addToCookie("APP","GROUPNUMBER",yourValue)
String.prototype.trim = function(){return
this.replace(/(^\s*)|(\s*$)/g, "")}
function parseCookie(name) {
var str = ""
var a = document.cookie.split(";")
for (var i=0; i<a.length; i++) {
a = a.trim()
if (a.substring(0,name.length) == name)
str = a.substring(name.length+1)
}
var a = str.split("&")
var obj = new Object()
if (str.length)
for (i=0; i<a.length; i++) {
temp = a.split("=")
obj[temp[0]] = temp[1]
} return obj
}
function addToCookie(cookieName,key,value) {
var cookies = parseCookie(cookieName)
cookies[key] = value
var d = new Date()
d.setFullYear(d.getFullYear()+1)
var cookieStr = cookieName + "="
for (var item in cookies)
cookieStr += item + "=" + cookies[item] + "&"
cookieStr = cookieStr.substring(0,cookieStr.length-1)
cookieStr = cookieStr + "; expires=" + d.toUTCString()
cookieStr = cookieStr + "; path=/"
document.cookie = cookieStr
}
function getCookie(name,key) {
var cookies = parseCookie(name)
return cookies[key]
}
(I get an error on the "for (i=0; i<a.length; i++)" line) Anyone have
code that works for cookies with keys?
Anyone got any code out there that will set and retrieve
cookie values that have the key/subKey structure?
Using the code provided below, examine
getCookie("APP","GROUPNUMBER")
and
addToCookie("APP","GROUPNUMBER",yourValue)
String.prototype.trim = function(){return
this.replace(/(^\s*)|(\s*$)/g, "")}
function parseCookie(name) {
var str = ""
var a = document.cookie.split(";")
for (var i=0; i<a.length; i++) {
a = a.trim()
if (a.substring(0,name.length) == name)
str = a.substring(name.length+1)
}
var a = str.split("&")
var obj = new Object()
if (str.length)
for (i=0; i<a.length; i++) {
temp = a.split("=")
obj[temp[0]] = temp[1]
} return obj
}
function addToCookie(cookieName,key,value) {
var cookies = parseCookie(cookieName)
cookies[key] = value
var d = new Date()
d.setFullYear(d.getFullYear()+1)
var cookieStr = cookieName + "="
for (var item in cookies)
cookieStr += item + "=" + cookies[item] + "&"
cookieStr = cookieStr.substring(0,cookieStr.length-1)
cookieStr = cookieStr + "; expires=" + d.toUTCString()
cookieStr = cookieStr + "; path=/"
document.cookie = cookieStr
}
function getCookie(name,key) {
var cookies = parseCookie(name)
return cookies[key]
}