What is wrong with this code so that it is not getting any cookies.
Code:
var nameEQ = donatehide + "="; //I'm going to search for the name of the cookie, followed by an =. So create this new string and put it in nameEQ
var ca = document.cookie.split(';'); //Then split document.cookie on semicolons. ca becomes an array containing all cookies that are set for this domain and path.
for(var i=0;i < ca.length;i++) { //Then go through the array (so through all cookies)
var c = ca[i]; //Set c to the cookie to be checked.
while (c.charAt(0)==' ') c = c.substring(1,c.length); //If the first character is a space, remove it by using the substring() method. Continue doing this until the first character is not a space.
if (c.indexOf(nameEQ) == 0) //Now string c begins with the name of the current cookie. If this is the name of the desired cookie...
{
var donatehide = c.substring(nameEQ.length,c.length); //...we've found what we were looking for. We now only need to return the value of the cookie, which is the part of c that comes after nameEQ. By returning this value we also end the function: mission accomplished.
}
}
if (!donatehide)
{
var donatehide = 0
}
function hidedonate()
{
if ($("#panel").hasClass("donatepanel"))
{
$('#panel').animate({right: "-145"}, 500)
$("#panel").removeClass("donatepanel").addClass("donatepanelhide")
document.cookie = "donatehide=0; expires=30; path=/"
}
else
{
$('#panel').animate({right: "-1"}, 500)
$("#panel").removeClass("donatepanelhide").addClass("donatepanel")
document.cookie = "donatehide=0; expires=30; path=/"
}
}
hidedonate() is run whenever I click a button to hide a 'donate' box. I can see that it is running because the box moves. I am also using jquery (hence the 'animate'). When donatehide = 1 the box will have a class change so that it is immediately hidden and I want to make these settings stay via cookies
Which hides it the box. I am using if (donatehide != 0) instead of if (donatehide = 1) because I tried that and it redefined donatehide to 1 every time
If you split document.cookie, you should split on "; " rather than ";".
The expires parameter has to be in a particular format, generated by the date.toUTCString method. Your value is probably setting a zero-lifetime cookie.
If you split document.cookie, you should split on "; " rather than ";".
The expires parameter has to be in a particular format, generated by the date.toUTCString method. Your value is probably setting a zero-lifetime cookie.
G.I.Y.F.
I don't think I did. The script here is copied and pasted directly from my script and it doesn't have that mistake in it.
Edit: ignore this comment I read your message wrong
Bookmarks