Click to See Complete Forum and Search --> : Load and Remember Background Images
dcale
12-05-2002, 04:31 PM
I am looking for a script to allow the user to select a background image by clicking on a text link or image map. Would also like to have an associated cookie which will remember the selected background image for their next visit.
Help greatly appreciated!
Dave Cale (decale@charter.net)
dcale
12-05-2002, 07:43 PM
Yes, I have checked may sites but am only able to find background "color" changers with cookies. I have a functional site that can remember background "color", but I want to be able to select and remember background "image".
Thanks!
Dave
dcale
12-06-2002, 10:07 PM
Have tried.........just not sure of what parts to change. Should be relatively simple, but not a hardcore coder.
Here's the cookie script:
<script>
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
// -->
</script>
Here's the script that the image map below references.
<script>
<!--
background = GetCookie('background')
if (background == "blue2") {document.bgColor="0042A5"; }
else if (background =="white"){ document.bgColor="ffffff"; }
else if (background =="grey"){document.bgColor="C6C6C6"; }
else if (background =="tan") { document.bgColor="ADAD8C"; }
else if (background =="blue1") { document.bgColor="00317B"; }
else if (background =="blue2") { document.bgColor="0042A5"; }
else { document.bgColor = "00317B"; }
// -->
</script>
Here's part of the image map code I'm using:
<map name="colorbar">
<area shape="rect" coords="5,5,13,11" HREF="#" ALT="white" onClick=" {
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31 * 9));
SetCookie('background','white', expdate);
document.bgColor='ffffff';
return false; } " >
dcale
12-07-2002, 02:46 PM
Thanks Dave!
Finally figured it out with a little help from you.
Thanks a bunch for pointing me in the right direction.
FYI....was able to use same cookie....just changed script from
document.bgColor="images/image1.gif";
to
document.body.background="images/image1.gif";
and made a few tweaks to my image map structure and whamo@*&^$*%
Thanks Dave!
I really appreciate it....:D :D
Lance Hall
04-19-2003, 08:36 PM
I am a javascript novice but I copied and modified exisiting scripts to allow a custom background on my genealogical site.
http://freepages.genealogy.rootsweb.com/~texlance/main.htm
Lance Hall