2
0
mirror of https://github.com/boostorg/website.git synced 2026-01-27 07:22:15 +00:00
Files
website/development/doc/javascript/cookies.js
Matias Capeletto 8d237bd14b safari fix
[SVN r7306]
2007-06-29 02:36:31 +00:00

54 lines
1.3 KiB
JavaScript

/*===========================================================================
Copyright (c) 2007 Matias Capeletto
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
===========================================================================*/
(function() {
/* Based on http://www.quirksmode.org/js/cookies.html */
function create_cookie( sName, sValue, nDays )
{
var sExpires;
if( nDays )
{
var dDate = new Date();
dDate.setTime( dDate.getTime() + ( nDays * 24*60*60*1000 ) );
sExpires = "; expires=" + dDate.toGMTString();
}
else
{
sExpires = "";
}
document.cookie = sName + "=" + sValue + sExpires + "; path=/";
}
function read_cookie(sName)
{
var sNameEq = sName + "=";
var aCookies = document.cookie.split(';');
for(var i=0, len = aCookies.length ; i < len ; i++ )
{
var oCookie = aCookies[i].replace(/^\s+/g, "");
if( oCookie.indexOf(sNameEq) == 0 )
{
return oCookie.substring( sNameEq.length, oCookie.length );
}
}
return null;
}
// Public Interface
boostscript.cookies.create = create_cookie;
boostscript.cookies.read = read_cookie;
boostscript.cookies.loaded = true;
})();