Search code examples
javascriptcookiesmootools

Cookie set on one page is not retained on other pages using Javascript


I have set a cookie:

Cookie.write('callstream', new Date, {
    path: '/',
    duration: 14,
    secure: false,
});

The cookie is set correctly on the page where i set the cookie, however once i visit a new page on the same domain the cookie is now NULL

FIXED:

Needed to ADD:

domain: '.domain.com'


Solution

  • This is because you aren't setting the domain when writing the cookie, as shown here:

    Cookie.write('callstream', new Date, {
        path: '/',
        duration: 14,
        secure: false,
        domain: '.domain.com'
    });