How do I set a cookie for the homepage only?

  • 0
    I'm using the js-cookie library, but the problem has nothing to do with the library. There is a pop-up window that appears if the user tries to leave the site, the site pages are landing pages, with the addresses: site.ru/page, site.ru/anotherpage, etc.

    The essence of the window is as follows: the user enters the site, if there is no showStopModal cookie, then we show the pop-up window, as soon as the window is closed, the cookies are hung in this way:
    Cookies.set('showStopModal', true, {path: window.location.pathname, expires: 1});

    The problem arises with the main page, since path in this case will be equal to / , then when saving path: / , the data cookies are distributed to all pages of the site, although they should be saved only for the main page, how can this be circumvented?
    JavaScript Alexandra Werner, Jul 31, 2020

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!