Forums
This topic is locked
Images controlled by time of day
Posted 10 Oct 2002 02:56:26
1
has voted
10 Oct 2002 02:56:26 Randy Huitema posted:
Hi,I am looking for some code to show an image according to the time of day on a web server. Any help would be greatly appreciated.
Replies
Replied 10 Oct 2002 20:56:13
10 Oct 2002 20:56:13 Ned Frankly replied:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<%
var d = new Date();
var Hours = d.getHours();
var ImageSource = "EveningImage.gif"
if (Hours>=0 && Hours<12) ImageSource = "MorningImage.gif"
%>
<html>
<head>
<title>Image By Time of Day</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<img src="images/<%=ImageSource%>">
</body>
</html>
Ned Frankly
<%
var d = new Date();
var Hours = d.getHours();
var ImageSource = "EveningImage.gif"
if (Hours>=0 && Hours<12) ImageSource = "MorningImage.gif"
%>
<html>
<head>
<title>Image By Time of Day</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<img src="images/<%=ImageSource%>">
</body>
</html>
Ned Frankly
Replied 10 Oct 2002 20:57:56
10 Oct 2002 20:57:56 Ned Frankly replied:
Geez, even charset (char-set) gets nailed by the profanity filter!
Since when is a-r-s-e that foul a word? I can type ASS with impunity (a much worse word in the states than a-r-s-e). <img src=../images/mxzone/forum/icon_smile.gif border=0 align=middle>
Ned Frankly
Since when is a-r-s-e that foul a word? I can type ASS with impunity (a much worse word in the states than a-r-s-e). <img src=../images/mxzone/forum/icon_smile.gif border=0 align=middle>
Ned Frankly
Replied 10 Oct 2002 23:54:32
10 Oct 2002 23:54:32 Randy Huitema replied:
Ned,
This code worked great, but I am using VBSCRIPT in my ASP pages, and when I insert my Recordsets it causes an error. You wouldn't happen to know the VBSCRIPT?
This code worked great, but I am using VBSCRIPT in my ASP pages, and when I insert my Recordsets it causes an error. You wouldn't happen to know the VBSCRIPT?
Replied 11 Oct 2002 03:59:37
11 Oct 2002 03:59:37 Ned Frankly replied:
Nope, call me a rebel but I try my best to stay away from VBScript. Most tutorials are written in it, DMX seems to prefer it, but I like JavaScript. I curse my Windows PC everyday, but alas, Macromedia hasn't ported MX to Linux yet. VB means Visual Basic means Redmond. Evil, pure and simple.
Actually, I do write passable VBScript when I must, but I wrote what I gave you in the language that I know well, so I hesitate to write it out in VBScript. It'll be a good exercise for you.
Hints:
IF statements in JavaScript don't need a THEN statement.
var MyVar="something" is Javascript for dim MyVar; set MyVar = "something"
Ned Frankly
Actually, I do write passable VBScript when I must, but I wrote what I gave you in the language that I know well, so I hesitate to write it out in VBScript. It'll be a good exercise for you.
Hints:
IF statements in JavaScript don't need a THEN statement.
var MyVar="something" is Javascript for dim MyVar; set MyVar = "something"
Ned Frankly
Replied 12 Oct 2002 21:00:24
12 Oct 2002 21:00:24 Randy Huitema replied:
Just wanted to post the code that I had some help to get running.
<%
Dim d : d = Time()
Dim Hours : Hours = DatePart("h",d)
Dim WDay : WDay = WeekDay(Date)
Dim ImageSource : ImageSource = "onairdefault.gif"
If Hours >= 5 AND Hours < 9 Then ImageSource = "daveandjacquie.gif"
If Hours >= 9 AND Hours < 14 Then ImageSource = "marklapointe.gif"
If Hours >= 14 AND Hours < 18 Then ImageSource = "chrisharding.gif"
If Hours >= 18 AND Hours < 23 Then ImageSource = "wendystevens.gif"
IF WDay = 7 AND Hours >= 0 AND Hours < 9 Then ImageSource = "onairdefault.gif"
IF WDay = 7 AND Hours >= 9 AND Hours < 12 Then ImageSource = "gordjohnson.gif"
IF WDay = 7 AND Hours >= 12 AND Hours < 24 Then ImageSource = "onairdefault.gif"
IF WDay = 1 AND Hours >= 0 AND Hours < 24 Then ImageSource = "onairdefault.gif"
%>
<%
Dim d : d = Time()
Dim Hours : Hours = DatePart("h",d)
Dim WDay : WDay = WeekDay(Date)
Dim ImageSource : ImageSource = "onairdefault.gif"
If Hours >= 5 AND Hours < 9 Then ImageSource = "daveandjacquie.gif"
If Hours >= 9 AND Hours < 14 Then ImageSource = "marklapointe.gif"
If Hours >= 14 AND Hours < 18 Then ImageSource = "chrisharding.gif"
If Hours >= 18 AND Hours < 23 Then ImageSource = "wendystevens.gif"
IF WDay = 7 AND Hours >= 0 AND Hours < 9 Then ImageSource = "onairdefault.gif"
IF WDay = 7 AND Hours >= 9 AND Hours < 12 Then ImageSource = "gordjohnson.gif"
IF WDay = 7 AND Hours >= 12 AND Hours < 24 Then ImageSource = "onairdefault.gif"
IF WDay = 1 AND Hours >= 0 AND Hours < 24 Then ImageSource = "onairdefault.gif"
%>