The Cookie class procedures are called to get or set a website cookie. It's great for website customization without requiring a visitor to sign in.
The draw back to this is that a cookie will expire. That means that if a visitor doesn't visit the website before the cookie expires, the visitor will need to configure the setting(s) again.
Note of caution
Cookies are restrictive locally when using ports because they don't differentiate a cookie. That means that localhost:80 and localhost:5050 share cookies, so when cookies have the same name they will change each others' cookie. This architecture's lack of port support is surprising to me, and is why a development box can't run more than one website in a stable state.
The class name is Cookie.
Calling a procedure would look something like: Cookie.GetCookie(CookieName)
There are two customized functions that come from W3Schools, GetCookie and SetCookie. The rest are GetCookie() embedded variants.
NOTE: All of the matching function parameters are of the same type.
- SetCookie(CookieName, CookieValue, CookieExpiresInDays)
- GetCookieValue(CookieName, CookieDefaultValue)
- GetCookieValueAndSetDaily(CookieName, CookieDefaultValue)
The following can easily be loaded with every page load, and will make it less likely for visitors to need to reconfigure all of their settings again. Simply add it to a script file, something like variables.js will work just fine.
var ModeDefault = 'day';
var ModeSetting = Cookie.GetCookieValueAndSetDaily( CookieMode, ModeDefault );
In the previous code CookieMode = CookieName, ModeDefault = CookieDefaultValue, and ModeSetting = CookieValue.
Self explanatory except for CookieExpiresInDays, which is the number of days before the cookie expires. 365 is used when GetCookieValueAndSetDaily() is called.
This function can be used to get a cookie value.
This will set a cookie to CookieDefaultValue when a cookie does not exist. CookieDefaultValue works with empty space ("") or null. If you don't need CookieDefaultValue, just use GetCookie().
This works the same as GetCookieValue(), and it will push the expiry date by another 365 days.