Hi there,
I use a popup window to select a background image for the main window.
[B]I want to set a cookie
a) to store the value of the choosen image, and
b) to read the cookie onload and set the stored image
Any ideas?
Thank you!
P.S.:
I write below:
a) the popup window code (that chooses the background image), and
b) the cookie code i have found
———————– START – popup window code ———————
<html>
<head>
<script language=”javascript” type=”text/javascript”>
function changebg(my)
{
opener.document.getElementById(“testdiv”).src = my;
}
</script>
</head>
<body>
<img src=”images1.jpg” width=”100″ height=”100″ onClick=”changebg(this.src)”/>
<img src=”images2.jpg” width=”100″ height=”100″ onClick=”changebg(this.src)” />
</body>
</html>
———————– END – popup window code ———————
———————– START – cookie code ———————
<script language=”javascript” type=”text/javascript”>
function getCookie(NameOfCookie)
{ if (document.cookie.length > 0)
{ begin = document.cookie.indexOf(NameOfCookie+”=”);
if (begin != -1)
{ begin += NameOfCookie.length+1;
end = document.cookie.indexOf(“;”, begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); }
}
return null;
}
function setCookie(NameOfCookie, value, expiredays)
{ var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24
document.cookie = NameOfCookie + “=” + escape(value) +
((expiredays == null) ? “” : “; expires=” + ExpireDate.toGMTString());
}
function delCookie (NameOfCookie)
{ if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + “=” +
“; expires=Thu, 01-Jan-70 00:00:01 GMT”;
}
}
</script>
———————– END – cookie code ———————