View Full Version : Animate Collpase DIV Problems clearing cookies.

06-21-2010, 05:33 PM
1) Script Title: Animated Collapse DIV 2.4

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/animatedcollapse.htm

3) Describe problem: It appears that the cookie for this script is set whenever someone leaves the page which means to clear the cookies for this script a person has to navigate away from the page and THEN clear their cookies for the cookie to actually be deleted and to me this is not the behavior I would expect. What I did expect is to be able to clear my cookies while the page is still open and then refresh the page the cookie remain cleared much like it is when using these forums. Is there anyway to alter the script so that it behaves in this manner.


06-22-2010, 04:31 AM
Hmm I'm not sure I completely understand. When you say "clear the cookies", do you mean manually deleting the cookie from the browser's toolbar? The cookie used in this script is session only, so its behavior is slightly different from that of say the forums, which is persistent.

06-22-2010, 05:59 AM
Sorry for any confusion and yes I mean manually deleting the cookie set by the script using the browser to delete the cookie and the reason the cookie is not session only is because I used your tip in this topic http://www.dynamicdrive.com/forums/showthread.php?t=46272 to make it persistent. Currently I have it set to save for 365 days.

That being said, the problem I am having is if I deleted the cookie (using my browser) and refreshed the page the divs do not revert to their original state (expanded in my case) because the cookie is being re-saved just before the page refreshes it seems and I would like to change this behavior so that if I delete the cookie and refresh the page then it will revert all my divs to their original state and only set the cookie again if any of the divs are altered in some way possibly using the Ontoggle event handler perhaps.

I am admittedly new to Js so I am not sure this would even work but my idea is to comment out the this.setCookie() lines in the script and add them to the Ontoggle event
function so that the cookie is only set after you change the state of a div but as I stated before this may not even be possible and my lack of Js experience doesn't help so I guess I just need to know if it's even possible to do what I need to do using the current script or not.

Thanks again for your time,

06-23-2010, 08:19 AM
Sorry for the bump but I really need to know if this is possible or not using the current version of this script because if it is not then I need to find another script that can do this.


06-23-2010, 08:14 PM
Ok, try the below modified .js file. It should reset the persistence if cookies are explicitly cleared, or if you change the number of days to persist from the existing setting (ie: from 5 days to 3 days instead).

Inside the .js file, the following line lets you set the number of days to persist:

persistdays: 5, //days to persist cookie

June 29th Reuploaded animatedcollapse.js, which contained a slight syntax error that's now fixed.

06-24-2010, 12:49 PM
Thanks but this does not seem to work. I deleted all of my cookies in firefox so I could make sure I was not mixing cookie names/values by mistake then I placed the new JS file you attached above in the directory where my old JS file was (I renamed the original file to animatedcollapse_original.jp just as a backup) and then I loaded my test page in the browser and these where my findings.

1.) All my divs were collapsed by a default which is not how they were in the original version of the script because I setup a css file to explicitly have them open by default using display: block for divs however this new script seems to ignore that and so they are closed by default and not sure why.

2.) If you delete your cookies while the page is still open the divs will not revert to their original states (as I said they would be closed in the new version of the script and open in the original version which is how I want them to be but that's another problem altogether I guess)

Anyway I created a little test package that you can look at yourself to see whats going on. Included in the package is.

The original animatedcollapse.js file (renamed to animatedcollapse_original.js)
The new animatedcollapse.js file
Some custom expand / collapse icons I created for my site.
An index.html file (with explanations of the problem) that you can use to test the scripts.
A CSS file named style.css which I used to style the divs and to set the initial state of the divs to be expanded using display block. (ignored in new version of the script)

Please take the time to look over my implantation of your script and let me know what I need to do to get it working as I would like.

Thanks Again,

06-25-2010, 07:01 PM
I hate to sound impatient but is there any update on this issue.

Thanks again,

06-28-2010, 09:32 PM
Just bumping this one last time to see if anyone can help me resolve this issue as it's been plaguing me for over a week now.

06-29-2010, 06:53 PM
Hmm that's strange. I looked over the modified animatedcollapse.js file again, which contained a slight syntax error (now fixed and file reuploaded). But the issue persists as far as deleting cookies not getting rid of the saved persistence setting. When I have time I'll come back to this to see if I can find the fault (in the next few days), though if this is a pressing issue, you may want to look at another script instead...