Hi there?
I am having a problem with creating a site wide cookie.
I want to create a cookie that i can increment as the user
browses through each page my website. I have tried to create a
function that i call in every page that creates and destroys the
cookie.
But this seems to create a new cookie for every different directory that is in the website (if two pages are in the same directory then only one cookie is produced). I presume this is because the cookie property is attached to the document
object. Is this right?
I have pasted the code I'm using below. There are 2 functions and then code that runs when each page loads.
How can I create a single cookie for the whole site that I can delete/create for each page the browser visits?
Thanks in advance,
Mark.
here is my code
function SetCookie(name,value) {
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
document.cookie = name + "=" + value + "; expires=" + exp.toGMTString(); + "; path=/;"
}
function DeleteCookie (name,value) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
document.cookie = name + "=" + value + "; expires=" + exp.toGMTString(); + "; path=/;"
}
var sCookie = document.cookie;
var iPos= sCookie.indexOf("e-s_survey="
if ( iPos == -1)
{
SetCookie("e-s_survey", 1)
}
else
{
var iPageCnt = parseInt(sCookie.substring(iPos+11,iPos+12))
DeleteCookie("e-s_survey", iPageCnt.toString())
if (iPageCnt == 4)
{
SetCookie("e-s_survey", 5)
}
else
{
if (iPageCnt == 10)
{
SetCookie("e-s_survey", 1)
}
else
if (iPageCnt < 98)
{
SetCookie("e-s_survey", iPageCnt + 1)
}
}
}
I am having a problem with creating a site wide cookie.
I want to create a cookie that i can increment as the user
browses through each page my website. I have tried to create a
function that i call in every page that creates and destroys the
cookie.
But this seems to create a new cookie for every different directory that is in the website (if two pages are in the same directory then only one cookie is produced). I presume this is because the cookie property is attached to the document
object. Is this right?
I have pasted the code I'm using below. There are 2 functions and then code that runs when each page loads.
How can I create a single cookie for the whole site that I can delete/create for each page the browser visits?
Thanks in advance,
Mark.
here is my code
function SetCookie(name,value) {
var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
document.cookie = name + "=" + value + "; expires=" + exp.toGMTString(); + "; path=/;"
}
function DeleteCookie (name,value) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
document.cookie = name + "=" + value + "; expires=" + exp.toGMTString(); + "; path=/;"
}
var sCookie = document.cookie;
var iPos= sCookie.indexOf("e-s_survey="
if ( iPos == -1)
{
SetCookie("e-s_survey", 1)
}
else
{
var iPageCnt = parseInt(sCookie.substring(iPos+11,iPos+12))
DeleteCookie("e-s_survey", iPageCnt.toString())
if (iPageCnt == 4)
{
SetCookie("e-s_survey", 5)
}
else
{
if (iPageCnt == 10)
{
SetCookie("e-s_survey", 1)
}
else
if (iPageCnt < 98)
{
SetCookie("e-s_survey", iPageCnt + 1)
}
}
}