Forum Moderators: open

Message Too Old, No Replies

link rotation based on time of day

         

reuben101

4:49 pm on Nov 26, 2003 (gmt 0)

10+ Year Member




Hey guys,

I need to change a link to an mp3 file based on time of day. I've not been able to find a simple script to do this at the script sites and my attempts of writing it myself have not been satisfactory.

Thanks in advance.

DrDoc

5:03 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How many different "times of day" are you looking for?

NeedScripts

5:05 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This might not be best solution, but if you want, you can use PhpAdsNew, it can do that and also take care of your advertising management..

NS

DrDoc

5:06 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a script I wrote a couple years ago. Simple, but I believe it does its job:

<script type="text/javascript">
now = new Date();
hour = now.getHours();
if(hour>18) { txt = "Good Evening"; }
else if(hour>12) { txt = "Good Afternoon"; }
else if(hour>3) { txt = "Good Morning"; }
else { txt = "Welcome"; }
document.write(txt);
</script>

Of course you can change the txt value to be whatever you want... I think you get how it works :)

<added> A server side solution is, of course, prefered. But, then you always run into problems with figuring out which time zone the person is in :( </added>

reuben101

5:23 pm on Nov 26, 2003 (gmt 0)

10+ Year Member



Thanks for the quick response.

I think three time slots will be fine. This is for a radio station with a regional audience so the time zone factor isn't much of an issue.

This is another stupid question, but how can I change the link the visitor goes to but not the image they click to get there? I'm far better at graphic design than coding... :)

DrDoc

7:07 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script type="text/javascript">
now = new Date();
hour = now.getHours();
if(hour>18) { txt = "Good_Evening.html"; }
else if(hour>12) { txt = "Good_Afternoon.html"; }
else if(hour>3) { txt = "Good_Morning.html"; }
else { txt = "Default.html"; }
document.write("<a href='"+txt+"'>Link image</a>");
</script>
<noscript><a href="Default.html">Link image</a></noscript>