Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
QuakeLive

Errata || Using The Cookie Library || Renewing The Cookie

Recommended Posts

Hi,

 

I tested the example " Using the Cookie Library"... also I saw this in errata :

 

2e3o16p.png

 

and everything works fine, but I think that now the cookie is not renewed since the setTheme(theme) function does not create (set) any cookie. And, in the book there is the following text:

 

However, as written, the theme cookie will expire in a week. By calling the setThemeCookie() function here, the cookie will be renewed for another week (from today), and the page will be updated. This keeps the user’s preferences retained so long as it hasn’t been more than a week since the user accessed the page.

 

But, in eratta it is not explained how to renew the cookie. What would be the best and most elegant way to do this? This is how I did:

window.onload = function() {
	'use strict';
	document.getElementById('aTheme').onclick = setThemeCookie;
	document.getElementById('bTheme').onclick = setThemeCookie;
	var value = COOKIE.getCookie('theme');
	if (value) {
		setTheme(value);
                var expire = new Date();
		expire.setDate(expire.getDate() + 7);
		COOKIE.setCookie('theme', value, expire);
	}
};

The original code was:

window.onload = function() {
        'use strict';
        document.getElementById('aTheme').onclick = setThemeCookie;
        document.getElementById('bTheme').onclick = setThemeCookie;
        var theme = COOKIE.getCookie('theme');
        if (theme) {
                setTheme(theme);
        }
};

2. I have another question:

  • the cookie was created (for example, I clicked on the link 'aTheme');
  • then I browsed to some other website (for example, I opened google.com);
  • and, finnaly, I oppened the same example (page) again (by entering path in a browser).

Why theme is not remembered, CSS is not loaded? I need to click, to choose theme again to load CSS on the page? This applies to both - the code downloaded from this website, and for my code.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...