To avoid losing all variables upon refresh, I’d like to set a simple cookie.
I tried a simple: document.cookie = “username=Max Brown”;
but getting an error “Cannot set properties of null (setting ‘cookie’)”
How is this best done in AppGyver?
Just an idea that came to mind, and what about this just for testing:
document.cookie = "name=value";
Where “name” is the name of the cookie and “value” is the value you want to assign to the cookie.
You can also set the expiration date of the cookie and the cookie path through additional options string. For example:
document.cookie = "name=value; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/
This will set the “name” cookie with the value “value” and mark it as expiring on the last day of the year 9999 for all routes in the application."
Yes that’s exactly what my test above is doing. It’s truing to affect “Max Brown” to a cookie “username”. But the browser gives that error that it can’t set properties.
Thank you @Piotr_Tesny
Thank you everyone!
Hello, please refer to the official documentation on java script cookies: Document.cookie - Web APIs | MDN;
However, please note that document object is not accessible from the Appgyver inline js module… With Appgyver if you need to retain values between app launches you need to use the storage methods. You may browse this forum for pointers on how to use storage…
I hope that helps;
Thank you @Piotr_Tesny, I appreciate the help
So the answer is that there is no management of cookies through AppGyver, and it should be done by Storage methods.