Load state from cookie

Hello All,

I am trying to save and load tree states from a cookie. This has to be done by every refresh. which is every click sadly.

I have multi trees on the page and so i made it like this

tree1.saveOpenStates(“tree1”);

This seems to work as my tree cookies are now seperated. The problem is that the user is clicking through a website and the url (path) changes so the cookies also change. It seems be some strange reactions and i think it might be because it creates more and more cookies…for each path again.

My goal is just to save the state and rebuild on the new page load, but only keep 1 state for each tree. Am i doing something wrong or how can i force it to override the same cookie, not create a new one all the time?

Kind Regards,

Martin

By default cookies are created for the whole domain, so “tree1” will point to the same saved state on all pages ( unless you are using multiple domains )

If issue still occurs - please share the full code snippet, how save state is saved and hot it is restored.

Hello Stanislav

Because i have 3 trees i made a seperated function to save them all at once.

The function looks like this

I found in the docs , that i could name the cookie, using the example above.

Then for each tree i use the second param from the loadXML function

tree100482.loadXML(‘urltoxmltree’,function(){tree100482.loadOpenStates(“tree100482”)});
tree100480.loadXML(‘urltoxmltree’,function(){tree100480.loadOpenStates(“tree100480”)});
tree100484.loadXML(‘urltoxmltree’,function(){tree100484.loadOpenStates(“tree100484”)});

For testing i used firefox and chrome on mac osx. I used firefox as it was easier to view my cookies. Our page constist of a main url which i will call domain A, a static url for loading javascript/css etc on domain B and sometimes jquery tries to call localhost…dunno why…think something todo with the jquery ui lib :confused:

What i see is the following
The app start on path “/”
I get 3 cookies for domain A on path / with the names above.
Then when the user goes to for example “/findmesomething” on domain A,it still works and the trees are loaded as they should. When somebody then goes to a third url on domain A “/findmesomethingmore”, i see in firefox firebug(view cookie information) i have 2 sets off cookies with the same name.
1 set for “/” and a second set for “/findmesomething”. After that it seems to load and restore something, but not the last request. I assume it gets confused which to pick and just picks 1.

If things are unclear or you have questions,please let me know.

Hopefully its something small and stupid that i am doing wrong.

Kind Regards

Martin

Try to change state saving command like next

tree100482.saveOpenStates("tree100482","path=/");

it will use the same path for all pages, that must eliminate cookie duplication

Hello Stanislav

This has resolved the issue for me. It is now working correctly.

Thank you for your help

Kind Regards,

Martin