344
/** Writes a JSONable object to the cookie under a particular key
345
* (JSON encoded and URL encoded).
347
function write_cookie(key, value)
349
var sendstr = encodeURIComponent(key) + "="
350
+ encodeURIComponent(JSON.stringify(value));
351
/* This actually just assigns to the key, not replacing the whole cookie
352
* as it appears to. */
353
document.cookie = sendstr;
355
/** Reads a cookie which has a JSONable object encoded as its value.
356
* Returns the object, parsed from JSON.
358
function read_cookie(key)
360
var cookies = document.cookie.split(";");
361
var checkstart = encodeURIComponent(key) + "=";
362
var checklen = checkstart.length;
363
for (var i=0; i<cookies.length; i++)
365
var cookie = cookies[i];
366
while (cookie[0] == ' ')
367
cookie = cookie.substr(1);
368
if (cookie.substr(0, checklen) == checkstart)
370
var valstr = cookie.substr(checklen);
371
valstr = decodeURIComponent(valstr);
372
return JSON.parse(valstr);
344
377
/** Given an argument map, as output in the args parameter of the return of
345
378
* parseurl, gets the first occurence of an argument in the URL string.
346
379
* If the argument was not found, returns null.