Cookiename with querystring
Cookiename with querystring
Hi Allan,
i have an Issue with the Cookiehandling which i solved by patching fnCreateCookie & fnReadCookie. Maybe useful for others or there is a hint solving it in another way...
Problem:
I have a unique Link. It differs only in the querystring e.g.
.../develop/index.php?modul=rank&ranking_id=3
.../develop/index.php?modul=rank&ranking_id=45
but i need different cookies for that. So i patched 1.6.2:
[code]
function _fnCreateCookie ( sName, sValue, iSecs )
{
var date = new Date();
date.setTime( date.getTime()+(iSecs*1000) );
/*
* Shocking but true - it would appear IE has major issues with having the path being
* set to anything but root. We need the cookie to be available based on the path, so we
* have to append the pathname to the cookie name. Appalling.
*/
sName += '_'+window.location.pathname.replace(/[\/:]/g,"").toLowerCase();
sName += window.location.search.replace(/[\/:=&]/g,"").toLowerCase();
document.cookie = sName+"="+sValue+"; expires="+date.toGMTString()+"; path=/";
}
[/code]
and
[code]
function _fnReadCookie ( sName )
{
var sNameEQ = sName +'_'+ window.location.pathname.replace(/[\/:]/g,"").toLowerCase() + window.location.search.replace(/[\/:=&]/g,"").toLowerCase() + "=";
var sCookieContents = document.cookie.split(';');
for( var i=0 ; i
i have an Issue with the Cookiehandling which i solved by patching fnCreateCookie & fnReadCookie. Maybe useful for others or there is a hint solving it in another way...
Problem:
I have a unique Link. It differs only in the querystring e.g.
.../develop/index.php?modul=rank&ranking_id=3
.../develop/index.php?modul=rank&ranking_id=45
but i need different cookies for that. So i patched 1.6.2:
[code]
function _fnCreateCookie ( sName, sValue, iSecs )
{
var date = new Date();
date.setTime( date.getTime()+(iSecs*1000) );
/*
* Shocking but true - it would appear IE has major issues with having the path being
* set to anything but root. We need the cookie to be available based on the path, so we
* have to append the pathname to the cookie name. Appalling.
*/
sName += '_'+window.location.pathname.replace(/[\/:]/g,"").toLowerCase();
sName += window.location.search.replace(/[\/:=&]/g,"").toLowerCase();
document.cookie = sName+"="+sValue+"; expires="+date.toGMTString()+"; path=/";
}
[/code]
and
[code]
function _fnReadCookie ( sName )
{
var sNameEQ = sName +'_'+ window.location.pathname.replace(/[\/:]/g,"").toLowerCase() + window.location.search.replace(/[\/:=&]/g,"").toLowerCase() + "=";
var sCookieContents = document.cookie.split(';');
for( var i=0 ; i
This discussion has been closed.