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
+ "; path=" + urlencode_path(root_dir);
352
/* This actually just assigns to the key, not replacing the whole cookie
353
* as it appears to. */
354
document.cookie = sendstr;
356
/** Reads a cookie which has a JSONable object encoded as its value.
357
* Returns the object, parsed from JSON.
359
function read_cookie(key)
361
var cookies = document.cookie.split(";");
362
var checkstart = encodeURIComponent(key) + "=";
363
var checklen = checkstart.length;
364
for (var i=0; i<cookies.length; i++)
366
var cookie = cookies[i];
367
while (cookie[0] == ' ')
368
cookie = cookie.substr(1);
369
if (cookie.substr(0, checklen) == checkstart)
371
var valstr = cookie.substr(checklen);
372
valstr = decodeURIComponent(valstr);
373
return JSON.parse(valstr);
378
344
/** Given an argument map, as output in the args parameter of the return of
379
345
* parseurl, gets the first occurence of an argument in the URL string.
380
346
* If the argument was not found, returns null.