-2

I need to set the domain for a cookie in javascript.

I've tried doing it like this:

<script>
function checkCookieChange() {
Cookies.set('storelocationChange', 'true','/' ,'.testsite.co.uk', {expires: 7});
};
</script>

But it's not setting the domain. Any ideas what I'm doing wrong?

MarmiK
  • 5,639
  • 6
  • 40
  • 49
MariaL
  • 1,112
  • 2
  • 16
  • 41
  • Possible duplicate of [How do I create and read a value from cookie?](https://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie) – david Jul 24 '18 at 09:32
  • 1
    Where are you executing this script? Meaning, what was the document this code is executed in loaded from …? – CBroe Jul 24 '18 at 09:33
  • Are you setting the domain to one that is valid for the URL that the page was loaded from? – Quentin Jul 24 '18 at 09:33
  • What is `Cookies.set`? That isn't a browser built-in. Tell us which library you are using. – Quentin Jul 24 '18 at 09:33

1 Answers1

-1

you code looks as if you are using https://github.com/js-cookie/js-cookie. if that's the case, this would work:

Cookies.set('storelocationChange', 'true', { expires: 1, domain: 'domain.com' });
itavq
  • 135
  • 9