Cookies in JavaScript

Permanent Link: Cookies in JavaScript 29. Juli 2009 Comment No Comment

Using in Cookies is rather complicated. All the cookies are in the string document.cookie. Here's a little static class I wrote a while ago to handle saving, reading and removing Cookies in JavaScript

/**
* Static Class for Cookie functions
*/
function Cookie()
{
}

/**
* Save new Cookie
*
* @param string name
* @param string value
* @param number days
*/
Cookie.save = function(name, value, days)
{
if (typeof days != 'undefined') {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
} else {
var expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
}

/**
* Read Cookie value
*
* @param string name
*/
Cookie.get = function(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1,c.length);
}
if (c.indexOf(nameEQ) == 0) {
return c.substring(nameEQ.length,c.length);
}
}
return null;
}

/**
* Delete Cookie
*
* @param string name
*/
Cookie.remove = function(name) {
Cookie.save(name,"",-1);
}

DNS Cache 1.5 released

Permanent Link: DNS Cache 1.5 released 13. Juli 2009 Comment Comments (3)

Today the latest version 1.5 of my Firefox plugin "DNS Cache" finally went public. Apart from Firefox 3.5 compatibility the following things have changed:

  • Explicitly flush DNS cache when deactivating
  • Toolbar Icon now has a context menu (right click): "Enable / Disable DNS Cache" and new:
  • "Flush DNS Cache": Flushes the DNS Cache no matter if the cache is disabled or not
  • Toolbar Icon now has to be double clicked in order to change the dns cache state

You can get the Firefox addon at the Firefox Add-ons page. If you've already installed it from there you should get the update automatically.

If you should experience any problems, please let me know!

< Juni 2009 | August 2009 >