Click to See Complete Forum and Search --> : Daily Image modified to background repeat


ChrisMacor
12-13-2002, 07:48 PM
I`ve got this script for changing an image daily

<script language="javascript1.1">

today = new Date();
day = today.getDay();

arday = new Array("Sunday.jpg", "Monday.jpg", "Tuesday.jpg", "Wednesday.jpg", "Thursday.jpg", "Friday.jpg", "Saturday.jpg");

document.write("<img src='" + arday[day] + "'>");

</script>

I want to change this so the image is fed into the background repeat element

<STYLE>
BODY { background-image: URL("");
background-repeat: repeat; }
</STYLE>

Any ideas on how to do this?

Thanks for your help,
Chris

ShrineDesigns
12-13-2002, 09:05 PM
this should do the trick
you don't need the CSS the bg repeats automaticly

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<script language="javascript1.1">
<!--

today = new Date();
day = today.getDay();
arday = new Array("Sunday.jpg", "Monday.jpg", "Tuesday.jpg", "Wednesday.jpg", "Thursday.jpg", "Friday.jpg", "Saturday.jpg");
document.body.background = arday[day];
//-->
</script>
</head>
<body onLoad="myFunction()">
</body>
</html>

ChrisMacor
12-14-2002, 07:42 PM
Thanks for your reply. That part about body onLoad seems to be unneccesary.
This is what worked for me.


</HEAD>
<BODY>


<script language="javascript1.1">

today = new Date();
day = today.getDay();

arday = new Array("Sunday.jpg", "Monday.jpg", "Tuesday.jpg", "Wednesday.jpg", "Thursday.jpg", "Friday.jpg", "Saturday.jpg");

document.body.background = arday[day];

</script>


</BODY>
</HTML>

I still havn`t gotten it to work on my website. I`m getting scripting errors even though it works by it self in a browser. There must be some conflict with existing script.
Anyway,
Thanks!

ShrineDesigns
12-14-2002, 09:03 PM
make sure the images a site or document relative
i.e. "myImageDirectoy/Sunday.jpg"

if the problem isn't that; post a link to the page of your site i'll take a look at it

ChrisMacor
12-16-2002, 06:15 PM
Hey, Thanks for your reply. It wasn`t working because of incomplete directory path. Thanks for the suggestion. I notice that Netscape 4.72 doesn`t support that javascript. Is that because their document object hierarchy is different?

Thanks again,
Chris

gil davis
12-16-2002, 06:45 PM
NS 4.x syntax:

document.tags.BODY.backgroundImage = filename;

must be executed *before* the body tag is read.

You can also use document.write() and dynamically create a body tag:

<script>
document.write('<BODY background=' + filename + '>');
</script>

in place of the HTML body tag.

ChrisMacor
03-27-2003, 04:30 PM
Hey Gil,
Thanks for your help. I`ll give this a try.
Chris