Is it ok to have more than one session cookie on a page/site (obviously with different names)? Are there any restrictions on this or any special actions to take?
I ask because I've one session cookie working perfectly, but the second one just doesn't want to work.
Yes there is a limit on cookies. I think all browsers limit them to 20 per domain.
Some browsers IE, opera have a 4K limit on the total amount of space taken up.
I'm sure you don't max this out with only two. Post code for the setting and reading of these cookies please.
<script type="text/javascript">
var min=12;
var max=24;
function zoomLetter(mysize) {
var p = document.getElementsByTagName('p');
for(i=0;i<p.length;i++) {
if(p[i].style.fontSize) {
var s = parseInt(p[i].style.fontSize.replace("px",""));
} else if(mysize>2) {
var s = mysize;
}else{
var s = 16;
}
if (mysize ==1){
if(s!=max) {
s += 1;
}
}
if (mysize ==-1){
if(s!=min) {
s -= 1;
}
}
if (mysize >2){
s=mysize;
}
p[i].style.fontSize = s+"px"
}
document.cookie="magnif="+s;
}
//Get cookie routine by Shelley Powers
function changeBGC(color){
document.bgColor = color;
document.cookie="bgcolor="+color;
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
// if cookie exists
if (offset != -1) {
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
if (get_cookie("bgcolor")!="")
changeBGC(get_cookie("bgcolor"))
if (get_cookie("magnif")!="")
zoomLetter(get_cookie("magnif"))
</script>
</head>
<body>
<div id="topbox"><img src="WFDA-headerright.gif" width="574" height="291" alt="headerright" /></div>
<div id="welcome">
<p>Welcome<br /><br />
Welcome to the Waltham Forest Dyslexia Association (WFDA). We are a grassroots charity that has been running since 1989 set up by concerned individuals – both parents of children with dyslexia and by teachers that specialise in dyslexia. Although we are affiliated with the British Dyslexia Associaiton (BDA) we are dependent on membership subscriptions, grants and fundraising.</p> </div>
<div id="welcome2">
<p>Our Vision<br /><br />
WFDA is committed to sending out a lifeline to people with dyslexia who often have nowhere else to turn. Our vision is that we will live in a dyslexic friendly society that enables dyslexic people of all ages to reach their full potential. </p>
</div>
<div id="welcome3">
<p>Our Aim <br /><br />
To support the needs of dyslexic children, young people and adults by providing an accessible, affordable, quality service run by appropriately trained staff. Also to advance the education of dyslexic people of all ages to help them to improve their confidence and independence as well as their well-being.</p>
</div>
<div id="header"><img src="WFDA-header.gif" width="630" height="291" alt="WFDA logo" /></div>
<div id="picture1">
</div>
<div id="background"><strong>Background colour</strong>
<table width="307" border="0" align="center" cellpadding="2">
<tr> <td width="13" bgcolor="#cccccc"><a href="#" onClick="javascript:changeBGC('#cccccc')"> </a> </td>
<td width="13" bgcolor="#ccccff"><a href="#" onClick="javascript:changeBGC('#ccccff')"> </a></td>
<td width="13" bgcolor="#ccffff"><a href="#" onClick="javascript:changeBGC('#ccffff')"> </a></td>
<td width="13" bgcolor="#99ffcc"><a href="#" onClick="javascript:changeBGC('#99ffcc')"> </a></td>
<td width="13" bgcolor="#3dffdd"><a href="#" onClick="javascript:changeBGC('#3dffdd')"> </a></td>
<td width="13" bgcolor="#88dd00"><a href="#" onClick="javascript:changeBGC('#88dd00')"> </a></td>
<td width="13" bgcolor="#ccff00"><a href="#" onClick="javascript:changeBGC('#ccff00')"> </a></td>
<td width="13" bgcolor="#eeee00"><a href="#" onClick="javascript:changeBGC('#eeee00')"> </a></td>
<td width="13" bgcolor="#ffcc00"><a href="#" onClick="javascript:changeBGC('#ffcc00')"> </a></td>
<td width="13" bgcolor="#cc9999"><a href="#" onClick="javascript:changeBGC('#cc9999')"> </a></td>
<td width="13" bgcolor="#ff9999"><a href="#" onClick="javascript:changeBGC('#ff9999')"> </a></td>
<td width="13" bgcolor="#ff99ff"><a href="#" onClick="javascript:changeBGC('#ff99ff')"> </a></td>
<td width="13" bgcolor="#ffcccc"><a href="#" onClick="javascript:changeBGC('#ffcccc')"> </a></td>
<td width="13" bgcolor="#ffffbb"><a href="#" onClick="javascript:changeBGC('#ffffbb')"> </a></td>
<td width="13" bgcolor="#FFFFFF"><a href="#" onClick="javascript:changeBGC('#FFFFFF')"> </a></td>
</tr>
</table>
<table width="108" border="0" align="center" cellpadding="2">
<tr>
<td width="50" height="49"> <h1 id="sprytrigger1"><a href="#" onclick="zoomLetter(1)">A+</a></h1></td>
<td width="44"><h3 id="sprytrigger2"><a href="#" onclick="zoomLetter(-1)">A-</a></h3></td>
</tr>
</table>
Both changeBGC and zoomLetter work within the page, but only the background colour is copied to another page when that's opened. The other page has the same script and zoomLetter works perfectly within that page.
For clarification, zoomLetter allows the user to increase or decrease the font size, one px at a time, between 14 and 24px.
I get the impression that either the cookie isn't stored or isn't called when the new page opens.
Last edited by Henry.; 01-11-2013 at 04:35 AM..
Reason: error in code..wasn't an error!
zoomLetter(mysize) does not seem to be working so I just made up a value of 2 to get a cookie for it. Your functions to make a cookie are the top two functions. I then added the w3shools code for reading them. did a on load thing and instead of changing the font and bgcolor I just used an alert to show you what the cookies are set to.
You can change the magnif to what ever you want to check it. But this is how it's done.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>New document</title>
<script type="text/javascript">
function zoomLetter(mysize) {
document.cookie="magnif="+8;
}
function changeBGC(color){
document.bgColor = color;
document.cookie="bgcolor="+color;
}
/*AND NOW*/
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function checkCookie()
{
var magnify = getCookie("magnif");
var thecolor = getCookie("bgcolor");
if (magnify != null && magnify != "" && thecolor != null && thecolor != "")
alert("the magnify is "+magnify+" and the color is "+thecolor);
}
</script>
<body onload="checkCookie()">
<div id="topbox"><img src="WFDA-headerright.gif" width="574" height="291" alt="headerright" /></div>
<div id="welcome">
<p>Welcome<br /><br />
Welcome to the Waltham Forest Dyslexia Association (WFDA). We are a grassroots charity that has been running since 1989 set up by concerned individuals – both parents of children with dyslexia and by teachers that specialise in dyslexia. Although we are affiliated with the British Dyslexia Associaiton (BDA) we are dependent on membership subscriptions, grants and fundraising.</p> </div>
<div id="welcome2">
<p>Our Vision<br /><br />
WFDA is committed to sending out a lifeline to people with dyslexia who often have nowhere else to turn. Our vision is that we will live in a dyslexic friendly society that enables dyslexic people of all ages to reach their full potential. </p>
</div>
<div id="welcome3">
<p>Our Aim <br /><br />
To support the needs of dyslexic children, young people and adults by providing an accessible, affordable, quality service run by appropriately trained staff. Also to advance the education of dyslexic people of all ages to help them to improve their confidence and independence as well as their well-being.</p>
</div>
<div id="header"><img src="WFDA-header.gif" width="630" height="291" alt="WFDA logo" /></div>
<div id="picture1">
</div>
<div id="background"><strong>Background colour</strong>
<table width="307" border="0" align="center" cellpadding="2">
<tr> <td width="13" bgcolor="#cccccc"><a href="#" onClick="javascript:changeBGC('#cccccc')"> </a> </td>
<td width="13" bgcolor="#ccccff"><a href="#" onClick="javascript:changeBGC('#ccccff')"> </a></td>
<td width="13" bgcolor="#ccffff"><a href="#" onClick="javascript:changeBGC('#ccffff')"> </a></td>
<td width="13" bgcolor="#99ffcc"><a href="#" onClick="javascript:changeBGC('#99ffcc')"> </a></td>
<td width="13" bgcolor="#3dffdd"><a href="#" onClick="javascript:changeBGC('#3dffdd')"> </a></td>
<td width="13" bgcolor="#88dd00"><a href="#" onClick="javascript:changeBGC('#88dd00')"> </a></td>
<td width="13" bgcolor="#ccff00"><a href="#" onClick="javascript:changeBGC('#ccff00')"> </a></td>
<td width="13" bgcolor="#eeee00"><a href="#" onClick="javascript:changeBGC('#eeee00')"> </a></td>
<td width="13" bgcolor="#ffcc00"><a href="#" onClick="javascript:changeBGC('#ffcc00')"> </a></td>
<td width="13" bgcolor="#cc9999"><a href="#" onClick="javascript:changeBGC('#cc9999')"> </a></td>
<td width="13" bgcolor="#ff9999"><a href="#" onClick="javascript:changeBGC('#ff9999')"> </a></td>
<td width="13" bgcolor="#ff99ff"><a href="#" onClick="javascript:changeBGC('#ff99ff')"> </a></td>
<td width="13" bgcolor="#ffcccc"><a href="#" onClick="javascript:changeBGC('#ffcccc')"> </a></td>
<td width="13" bgcolor="#ffffbb"><a href="#" onClick="javascript:changeBGC('#ffffbb')"> </a></td>
<td width="13" bgcolor="#FFFFFF"><a href="#" onClick="javascript:changeBGC('#FFFFFF')"> </a></td>
</tr>
</table>
<table width="108" border="0" align="center" cellpadding="2">
<tr>
<td width="50" height="49"> <h1 id="sprytrigger1"><a href="#" onclick="zoomLetter(1)">A+</a></h1></td>
<td width="44"><h3 id="sprytrigger2"><a href="#" onclick="zoomLetter(-1)">A-</a></h3></td>
</tr>
</table>
</body>
</html>