The purpose of my application is to require a website visitor to complete
a form before participating in a search application. I have a specific
reason for doing this with client-side javascript, but I'm not going to
go into the explanation of "why."
Ideally, the visitor goes to http://www.hopelandinc.com/golf-homes.html.
If they haven't registered in 90 days, they'll be redirected to a
registration form. Once they complete the reg form, they'll have a cookie
set (called "isRegistered") and be taken back to the golf homes page.
For testing purposes, it is not necessary to actually complete the form.
You can go to the golf-homes.html page, which will set the regReturn
cookie, and then bypass the form submission by going directly to
http://hopelandinc.com/registration-thanks.html
In short, it ain't working. (IE 6 test).
golf-homes.html calls the function securePage() below, which sets
regReturn and redirects to search-registration.html.
search-registration is a form that posts to an ASP script, then redirects
to registration-thanks.html
registration-thanks.html calls the function addRegistrationCookie which
adds the isRegisteredCookie, and then redirects to the value stored in
regReturn.
I've been trying to figure out why it doesn't work all day, and can't
find the problem. Hopefully some super-genius here will be able to help!
TIA, code below
Ziggy
Here is the function I'm using to retrieve a cookie value ("regReturn")
and redirect to a specified web page:
function addRegistrationCookie() {
var now= new Date();
var expDate = new Date(now.setDate(now.getDate() + 90));
expDate = expDate.toString();
makeCookie("isRegistered", "exists", expDate)
if (readCookie("regReturn")!='none') {
this.window.location.href = readCookie("regReturn");
}
}
The cookie is created when this function is called:
function securePage(cName, rLink) {
var now = new Date();
var expDate = now.setDate(now.getDate() + 90);
expDate = expDate.toString();
var loc = this.window.location.href;
makeCookie("regReturn", loc, expDate);
if (readCookie(cName)!="exists") {
this.window.location.href=rLink;
}
}
If I test the makeCookie function, it appears to store the cookie. Here
is the function:
function makeCookie(cName, cVal, cexpDate) {
document.cookie = cName + "=" + cVal +"; expires=" + cexpDate;
}
But when I try to read the cookie, I get no value. Here is the reader
(called on another web page)
function readCookie(cName){
var allcookies = document.cookie;
cName = cName + "=";
var pos=allcookies.indexOf(cName);
var retVal = "none";
if (pos!=-1) {
var start=pos+cName.length;
var end=allcookies.indexOf(";", start);
if(end==-1) end = allcookies.length;
var value=allcookies.substring(start, end);
value=unescape(value);
retVal=value;
}
return retVal;
}