Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

background for each day of the year

Status
Not open for further replies.

jrh0204

Technical User
May 31, 2007
1
US
so i want a background that changes each day. and ideally i wouldnt' be using an array for this.. and instead could just do something like...

var d = new Date()
document.write("<body background='"d.getMonth(),d.getDate()".jpg'>")

with the images in the same directory being named 01.jpg for jan 1st, 031.jpg for jan 31st, etc. etc.

but i know nothing about the syntax or structure that that would require. i think my non-working example should at least explain what i want to accomplish... can someone tell me how i can do this? i know it's possible... i've seen every element i need in other scripts, but i just don't know how to make them all work together without getting a bunch of errors... :(

p.s. this is actually on my windows desktop, not a website. it seems like some scripts won't work in an html set as the desktop background, but will on a webpage.. so thats weird too...
 
Hi

I would use the below script and would just put the [tt]body[/tt] statically. Chose one from Greg's list this, because your approach is not valid HTML :
Code:
<script type="text/javascript">
d=new Date().getDate();
if (d<10) d='0'+d;
window.onload=function(){document.body.style.backgroundImage='url('+d+'.gif)'}
</script>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top