dev00
07-08-2003, 09:09 PM
Hello,
I am struggling with trying to Sotre Multiple Values in a single Cookie. I need it to store and look something like the following:
SetCookie("CookieName", "usernameOne|singleID1|singleID2|singleID3:usernameTwo|singleID1:usernameThree|singleID3|singleID2");
Any help is appreciated!
Thanks!
Khalid Ali
07-08-2003, 09:11 PM
This page will detail the functionality..
http://68.145.35.86/skills/javascripts/CompleteCookieUseage.html
dev00
07-09-2003, 12:49 PM
Hey Khalid,
Thanks for your response, I've been through your code and unfortunately I'm still having trouble trying to figure it out. This is what I have to do:
All in a single cookie, I need to store various mutilple user IDS (IE browser is used on a single computer, with mulitply users logging in/out to use it). So, when a user logs in, their User ID gets stored in the cookie (lets name the cookie "cookie_name"). Now, associated with each USER ID are mulitply pop up window names that need to be stored.
Basically, a user is going to come into the site and get forced to view mulitply pop-ups throughout the pages of the site. Once they complete and close one, then "cookie_name" gets set with that pop-up name associated with the user id. So when the user returns another day, they will never again be forced with that particular pop-up...but will be forced to see the others that they have not completed....
So I think it looks something like this:
SetCookie("Cookie_Name", " usernameOne|popup1|popup2|popup3:
usernameTwo|popup1:
usernameThree|popup3|popup2
");
Now, I know how to call the popups, etc and now how to send the lesson Name and User ID to the cookie....but not sure how to capture it, store it, split it, etc.
If you can help again...THANKS!
This is the code that I have so far....currently it only creates a cookie and stores one name/value.
function checkInstructPop(instWindowURL,instWindowName,instruct_popup) {
var instruct_popup = GetCookie('ck_pb_instruct_popup');
if (instruct_popup == null) {
fnCallDialog(instWindowURL,instWindowName);
}
}
function setInstructPop(LessonName,pbUrl) {
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var ckArray = GetCookie("ck_pb_instruct_popup");
var UserName = "";
var LessonName = "";
if(ckArray!=null && ckArray.length>0) {
LessonName = ckArray[0];
createCookie (ckArray[0]);
}else{
createCookie (ckArray[0]);
}
parent.window.close();
top.opener.location.href = pbUrl;
}
function getCookie (CookieName) {
var cname = CookieName + "=";
var i = 0;
while (i < document.cookie.length) {
var j = i + cname.length;
if (document.cookie.substring(i, j) == cname){
var leng = document.cookie.indexOf (";", j);
if (leng == -1) {
leng = document.cookie.length;
}
return (unescape(document.cookie.substring(j, leng))).split("`");
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
}
function createCookie (val) {
var cookieName= "ck_pb_instruct_popup";
UserName +=1;
var UserName = new Date();
expire.setTime (expireIn + parseInt(expire.getTime())); //1 mins from now!
var WholeCookie = val + '`'+(LessonName)+'`'+thisVisit.getTime();
document.cookie = cookieName+"=" + escape (WholeCookie) + "; expires=" + expire.toGMTString();
}
function deleteCookie(Name){
var expire = new Date();
expire.setTime(expire.getTime() -2 * 86400001);//set date to 2 days ago
document.cookie = Name + "=*; expires=" + expire.toGMTString();
}
//generic cookie functions
var expDays = 3600;
function GetCookie (name) {
var arg = name + "=";
var arglen = arg.length;
var cooklen = document.cookie.length;
var i = 0;
while (i < cooklen) {
var j = i + arglen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function fnCallDialog(instWindowURL,instWindowName) {
instWindowHandle = showModelessDialog(instWindowURL,instWindowName,"status:no;dialogWidth:620px;dialogHeight:600px;edge:raised;resizable:yes;help:no;");
if (!instWindowHandle.opener)
instWindowHandle.opener = self;
}