/    Sign up×
Community /Pin to ProfileBookmark

Help!! Load image by timedate??

Hi,

I am in a pinch with this situation. A client wants to change a few images on his website at a rediculous time when we are all sleeping and I need a script that can automatically do this for me while we are sleeping. I will already have the images in the image folder but just want to switch them out automatically by giving a time and date ( i assume from that particular computers date/time).

Is this difficult to implement? Can anyone help or give me a reference?

Thanks so much!

Kreven

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@krevenauthorJun 29.2007 — Figured it out!

Here are the results:

javascript code:

[CODE]

//MAIN IMAGE
function changeImg01(imgNew,imgOld) {
var ck=timeTest(); // calls to check time, returns true/false
var mImg; // put the specific image into this variable

if(ck==true) { mImg=imgNew; } else { mImg=imgOld; }
document.write('<img src="' + mImg + '" width="390" height="381">'); // here you should edit the width and height
}

function timeTest() {

month = 'June'; // change the month to the one you want in the same format as shown
date = '29'; // change the date to the one you want in the same format as shown
year = '2007'; // change the year to the one you want in the same format as shown

theDate = month + ' ' + date + ' ' + year;

now = new Date();
setdate = new Date(theDate);

timer = (setdate - now) / 1000 / 60 / 60 / 24;
timer = Math.round(timer);

if (timer >= "1") return false; // if before the date use original image
if (timer <= "0") return true; // if on or after the date change image

}

[/CODE]


put in HTML where you want the image to be replaced (first parameter is the new img, the second is the original one):

[code=html]
<script language="javascript" type="text/javascript">
changeImg01("topimg/illust_sum.jpg","topimg/illust_spr.jpg");
</script>
[/code]


Repeat the function "changeImg01" to be "changeImg02", and rinse.

Hope this helps other people that want to do this. Its not perfect but it gets the job done.

Cheers,

Kreven
×

Success!

Help @kreven spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...