Lantrax
asked on
Javascript Cookies
When i take the cookie part out i don't get an error. When i add it i do.
I want to set the cookie and read it.
THis only has to work in IE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script language="javascript">
if ReadCookie('LeftNavState') == '' {
SetCookie( 'LeftNavState', 'none', '1' );
alert(ReadCookie('LeftNavS tate'));
}
function SetCookie(cookieName,cooki eValue,nDa ys) {
var today = new Date();
var expire = new Date();
if (nDays==null || nDays==0) nDays=1;
expire.setTime(today.getTi me() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cook ieValue)
+ ";expires="+expire.toGMTSt ring();
}
function ReadCookie(cookieName) {
var theCookie=""+document.cook ie;
var ind=theCookie.indexOf(cook ieName);
if (ind==-1 || cookieName=="") return "";
var ind1=theCookie.indexOf(';' ,ind);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substri ng(ind+coo kieName.le ngth+1,ind 1));
}
function toggleDisplay(id)
{
var elm = document.getElementById(id );
if (elm != null)
{
var d = elm.style.display;
elm.style.display = (d == 'none') ? 'block' : 'none';
if (elm.style.display == 'block') {
//alert('here 1');
document.getElementById('i mgShowHide ').src= 'Hide.jpg';
} else {
//alert('here 2');
document.getElementById('i mgShowHide ').src= 'Show.jpg';
}
}
}
</script>
<body >
<form id="form1">
<script language="JavaScript">
<!--
testValue=Math.floor(1000* Math.rando m());
SetCookie('AreCookiesEnabl ed',testVa lue);
if (testValue==ReadCookie('Ar eCookiesEn abled'))
document.write('<b>Cookies are currently enabled in your browser.</b>');
else document.write('<b>Cookies are not currently enabled in your browser.</b>');
//-->
</script>
<br /><br />
<table>
<tr>
<td id="tdLeftNav"><a href="page2.html">Page 2</a></td>
<td>
<div onclick="toggleDisplay('td LeftNav'); " style="CURSOR: hand">
<img src="Hide.jpg" border="0" id="imgShowHide" name="imgShowHide" />
</div>
</td></tr>
</table></form>
</body>
</html>
I want to set the cookie and read it.
THis only has to work in IE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script language="javascript">
if ReadCookie('LeftNavState')
SetCookie( 'LeftNavState', 'none', '1' );
alert(ReadCookie('LeftNavS
}
function SetCookie(cookieName,cooki
var today = new Date();
var expire = new Date();
if (nDays==null || nDays==0) nDays=1;
expire.setTime(today.getTi
document.cookie = cookieName+"="+escape(cook
+ ";expires="+expire.toGMTSt
}
function ReadCookie(cookieName) {
var theCookie=""+document.cook
var ind=theCookie.indexOf(cook
if (ind==-1 || cookieName=="") return "";
var ind1=theCookie.indexOf(';'
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substri
}
function toggleDisplay(id)
{
var elm = document.getElementById(id
if (elm != null)
{
var d = elm.style.display;
elm.style.display = (d == 'none') ? 'block' : 'none';
if (elm.style.display == 'block') {
//alert('here 1');
document.getElementById('i
} else {
//alert('here 2');
document.getElementById('i
}
}
}
</script>
<body >
<form id="form1">
<script language="JavaScript">
<!--
testValue=Math.floor(1000*
SetCookie('AreCookiesEnabl
if (testValue==ReadCookie('Ar
document.write('<b>Cookies
else document.write('<b>Cookies
//-->
</script>
<br /><br />
<table>
<tr>
<td id="tdLeftNav"><a href="page2.html">Page 2</a></td>
<td>
<div onclick="toggleDisplay('td
<img src="Hide.jpg" border="0" id="imgShowHide" name="imgShowHide" />
</div>
</td></tr>
</table></form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.