1

For example, the user can change the font size, and it is remembered in the cookies. Say I am on the product page and change the font size there and add the cookie. Everything looks fine, but when I go to the front page, the font size is back to normal. Going back to the product page, the cookie is applied. How can I make the cookies work site-wide instead of per page? Or is there something wrong with what I am doing?

How I do it is, when the user checks a checkbox:

$.cookie('font', 'x2');

And on $(document).ready() I simply check the cookie and apply the css so:

if($.cookie('font') == 'x2') {
  $(body).css('font-size', '200%');
}

Or something like that. I don't think the problem is in my code though anyway, since it works, is this some kind of Drupal behaviour or...?

5
  • No it's not a Drupal behaviour, I use jQuery cookie in plenty of sites without any problems
    – Clive
    May 22, 2013 at 15:36
  • Check if you have javascript errors when page loads
    – Aboodred1
    May 22, 2013 at 15:36
  • I don't have any javascript errors. I apply the font-size change and add the cookie and when I switch to any other page on the site, the cookie displays empty.
    – Sergo
    May 22, 2013 at 15:39
  • Try different machine/browser combinations to rule out local issues
    – Clive
    May 22, 2013 at 15:41
  • Same thing everywhere.
    – Sergo
    May 22, 2013 at 15:43

2 Answers 2

2

Not really Drupal related, but it sounds to me like you are only setting the cookie for the current path.

Change:

$.cookie('font', 'x2');

to:

$.cookie('font', 'x2', { path: Drupal.settings.basePath });
4
  • Still not working... This is driving me nuts. Tried setting the path to the base path and anything I could think of, doesn't seem to be it.
    – Sergo
    May 22, 2013 at 17:05
  • Is '/' the root of your drupal installation? Regardless, a more correct value for the cookie path (assuming you want the cookie available across your entire site) would make use of Drupal's global javascript settings in Drupal.settings. I've update my answer accordingly. May 22, 2013 at 17:28
  • This almost works. I will update the original post for further info.
    – Sergo
    May 23, 2013 at 6:36
  • I don't remember what didn't work for me, but I got it fixed. Your solution fixed this issue. Thank you.
    – Sergo
    May 30, 2013 at 13:16
0

Set a timeout of a certain number of days on the cookie:

$.cookie('font', 'x2', { expires : 10 });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.