Need Cookie Help

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/68849?pagenum=1
05 November 2025, 09:00

Topic


leatherlips
Need Cookie Help
11 August 2009, 21:40


I have made a link in the forum that opens a pop up. The pop up brings up a "Terms and Conditions" page. The member has to agree in order to proceed to the "Main Page".
What I am trying to do is have the "Terms and Conditions" page only appear once during the browser session if they agree. So if they click the popup link again they will go right to the "Main Page".
I'm not sure how to write the cookie to do that or where to place the code.

 

Replies ...


leatherlips
14 August 2009, 21:33


I think I have it working. I found this script and it seems to be working OK. I have one question though. The part in red seems a bit clumsy:
Code:
var expDays = 1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
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();
}

var favorite = GetCookie('uploadagree');

if (favorite != null) {
switch (favorite) {
case 'uploadagree' : url = 'pop_upload_new.asp';
break;
case 'nonexist' : url = 'nonexist.html';
break;
}
window.location.href = url;
}

The part:
Code:

      break;
case 'nonexist' : url = 'nonexist.html';
break;
was added to make it work because the original script had several choices. Since I only have one checkbox (uploadagree) I made up another one (nonexist) to get it to work. Is there a way to rewrite that to not use a case?
© 2000-2021 Snitz™ Communications