1

The following simple javascript code in a GAS gadget does not appear to work:

document.cookie="username=John Smith; expires=Mon, 31 Aug 2015 12:00:00 UTC; path=/";

Is this one of those sandbox things that I'm not allowed to do? If so, is there an alternative or workaround?

brock
  • 439
  • 1
  • 5
  • 17
  • 1
    May be similar to this question: [stackoverflow cookies apps script](http://stackoverflow.com/questions/12416286/set-custom-cookies-using-google-apps-script?rq=1) – Alan Wells Jul 16 '15 at 03:20
  • And this question [how to create cookie on google site](http://stackoverflow.com/questions/20355629/how-to-create-a-cookie-on-a-google-site) Although, I'm not sure if it was ever answered. – Alan Wells Jul 16 '15 at 03:26
  • @SandyGood Thanks. Your first suggestion would not work. That would allow a logged in google user to save properties. There is no google logging in on my site. Your second suggestion was never answered. I found that too. – brock Jul 16 '15 at 04:36
  • 1
    The answer is yes, you can. Simply set the domain property of your cookie to ".googleusercontent.com". However, the cookie is always deleted when I refresh the page, regardless of the expires string. Forgive me if I'm being dense, but that's not supposed to happen, right? Otherwise, what's the point of an expiry date at all? – brock Jul 16 '15 at 04:41

1 Answers1

1

The answer is yes, you can. Simply set the domain property of your cookie to ".googleusercontent.com".

However, for me, the cookie is always deleted when I refresh the page, regardless of the expires string. I don't know why this is happening, but I no longer care. I have found a different solution to the underlying problem of saving an email address client side: HTML5 local storage.

brock
  • 439
  • 1
  • 5
  • 17