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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I schedule a link change? 1

Status
Not open for further replies.

Usalabs1

Technical User
Jun 29, 2003
131
US
I run a radio station, and for 2 days, fridays and saturdays, the system is shutdown for routine maintenance, and resume service on sunday morning, ordinarily, I have a link to the radio station on one of the pages, that I would have to change manually, but the problem is, I would like to be able to schedule an event (for example, to start on a thursday at 1:30pm) that would automatically change the link to a page (on that day), that notifies the viewer that the station is down for maintenance, then on sunday morning at 8:00am the original link is restored to point to my radio station page, this scheduled event must be repetative, so that every thursday afternoon at a preset time (regardless of date) the event would change the link, then on every sunday (regardless of date) at a preset time, it would restore the original link until the next scheduled event, then it would repeat.

Is this possible?
 
Yes it is possible but the solution has nothing to do with HTML.

Are you using UNIX? Perhaps create two versions of the page, a "normal" version and a "maintenance" version. Put for the file extention of the "normal" one .html and for the "maintenace" one .html.off

Then set up cron jobs with shell scripts that renames the files so that the other one ends in .html and the first one ends in .html.off.

However, to me it sounds like a job for some dynamic scripting language (such as PHP or ASP) if you're willing to learn that.

I REALLY hope that helps.
Will
 
or just have your index file check the server time and redirect to the "offline" page during your maintenance hours.

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 

It can be done easily with Javascript, although you must realise that any client-side solution that needs to rely on date or time information can easily be spoofed if the user changes their time.

Let me know if you'd like the code anyway... But server-side is definately the way to go.

Dan
 
apatterno.........I'm using a windows webserver.

BillyRayPreachersSon..........Yes I would like the script, thankx.

jemminger........I don't know how to set the index file to do that.
 
save this file as "index.asp"

Code:
<%
	dim bOffline
	
	select case weekday(date())
		rem Su
		case 1
			bOffline = (hour() < 8)

		rem M, T, W
		case 2, 3, 4
			bOffline = false
			
		rem Th
		case 5
			bOffline = (time() >= timevalue("13:30:00"))
			
		rem F, Sa
		case 6, 7
			bOffline = true
	end select
	
	if bOffline
		response.redirect("offline.html")
	end if
%>
<html>
  <body>welcome to my site</body>
</html>

between Thursday after 1:30pm and Sunday 8am, visitors will be redirected to "offline.html", else they will see index.asp.

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Here's the Javascript version:

Code:
<html>
<head>
<script type="text/javascript">
<!--
	var startDay = 4;		// Start Day:  0 - 6 (Sun = 0, Mon = 1 ... Fri = 5, Sat = 6)
	var startHour = 13;		// Start Hour: 0 - 23
	var startMin = 30;		// Start Min:  0 - 59
	var endDay = 0;			// End Day:    0 - 6 (Sun = 0, Mon = 1 ... Fri = 5, Sat = 6)
	var endHour = 8;		// End Hour:   0 - 23
	var endMin = 0;			// End Min:    0 - 59

	function checkTime()
	{
		var startTimeDate = new Date(2004, 01, 01, startHour, startMin, 00);
		with (startTimeDate) while (getDay() != startDay) setDate(getDate()+1);
		var startTimeDateMsecs = startTimeDate.getTime();

		var endTimeDate = new Date(2004, 01, 01, endHour, endMin-1, 00);
		with (endTimeDate) while (getDate() < startTimeDate.getDate()) setDate(getDate()+1);
		with (endTimeDate) while (getDay() != endDay) setDate(getDate()+1);
		var endTimeDateMsecs = endTimeDate.getTime();

		var now = new Date();
		var currentTimeDate = new Date(2004, 01, 01, now.getHours(), now.getMinutes(), 00);
		with (currentTimeDate) while (getDate() < startTimeDate.getDate()) setDate(getDate()+1);
		with (currentTimeDate) while (getDay() != now.getDay()) setDate(getDate()+1);
		var currentTimeDateMsecs = currentTimeDate.getTime();
		return (!(currentTimeDateMsecs >= startTimeDateMsecs && currentTimeDateMsecs <= endTimeDateMsecs));
	}
//-->
</script>
</head>
<body>
	<a href="[URL unfurl="true"]http://www.google.co.uk/">Visit[/URL] Google</a>
	<br>
	<a href="[URL unfurl="true"]http://www.yahoo.co.uk/"[/URL] onclick="return(checkTime());">Visit Yahoo (except from Thu 13:30 until Sun 08:00)</a>
</body>
</html>

I've given two links as an example. The one without the onclick event has no restrictions, but the other one will not function if you are within the restricted date/times.

I've tested it with a few scenarios, but I'm sure that you can test it through, anyway.

Hope this helps,
Dan
 
the script doesn't do what I posted earlier.

I'll try to explain it using snippets from BASIC.

t$=current day:ti$=current time
link1$="<a href>=" of default page">HERE</a>
link2$="<a href="offline.htm">HERE</a>
if t$="Thur" and ti$>="13:30" then physically_change <a href=" of default page">HERE</a> to link2$
else
leave link as is, but if changed by checking routine, restore original link.

Even though the above code will not work, the idea is there.

To explain the code, 2 variables would hold the current day and time, then a small routine would check the day and time against a predefined set of variables, and if they match the '<a href></a>' address, code in an html document would be physically changed by the script to reference another document, but if the checking routine deosn't match, then the '<a href></a>' address code is not changed, but if changed, then the original link is restored.

The text within the '<a href="blah blah blah">TEXT</a>' is not changed in anyway.

That means, when someone clicks on the link on either fri or sat at anytime of the day, the link would change (invisibily) and load a different web page, but when someone clicks on the same link on either sun,mon,tues,wed, or thur at anytime of the day, the original assigned web page opens. This should happen completely invisible to the user.
 
Nice of you to have a stab at modifying it yourself, considering that most of the groundwork was already done in that post, and only 3 lines needed modifying ;o)

Here's a replacement version:

Code:
<html>
<head>
<script type="text/javascript">
<!--
	var startDay = 4;		// Start Day:  0 - 6 (Sun = 0, Mon = 1 ... Fri = 5, Sat = 6)
	var startHour = 13;		// Start Hour: 0 - 23
	var startMin = 30;		// Start Min:  0 - 59
	var endDay = 0;			// End Day:    0 - 6 (Sun = 0, Mon = 1 ... Fri = 5, Sat = 6)
	var endHour = 8;		// End Hour:   0 - 23
	var endMin = 0;			// End Min:    0 - 59

	function alternateLink(linkObj)
	{
		var startTimeDate = new Date(2004, 01, 01, startHour, startMin, 00);
		with (startTimeDate) while (getDay() != startDay) setDate(getDate()+1);
		var startTimeDateMsecs = startTimeDate.getTime();

		var endTimeDate = new Date(2004, 01, 01, endHour, endMin-1, 00);
		with (endTimeDate) while (getDate() < startTimeDate.getDate()) setDate(getDate()+1);
		with (endTimeDate) while (getDay() != endDay) setDate(getDate()+1);
		var endTimeDateMsecs = endTimeDate.getTime();

		var now = new Date();
		var currentTimeDate = new Date(2004, 01, 01, now.getHours(), now.getMinutes(), 00);
		with (currentTimeDate) while (getDate() < startTimeDate.getDate()) setDate(getDate()+1);
		with (currentTimeDate) while (getDay() != now.getDay()) setDate(getDate()+1);
		var currentTimeDateMsecs = currentTimeDate.getTime();

		if (currentTimeDateMsecs >= startTimeDateMsecs && currentTimeDateMsecs <= endTimeDateMsecs) linkObj.href = '[URL unfurl="true"]http://www.tek-tips.com/';[/URL]
	}
//-->
</script>
</head>
<body>
	<a href="[URL unfurl="true"]http://www.google.co.uk/">Visit[/URL] Google</a>
	<br>
	<a href="[URL unfurl="true"]http://www.yahoo.co.uk/"[/URL] onclick="alternateLink(this);">Visit Yahoo</a>
</body>
</html>

Dan
 
The code is still using 2 links.

I run a radio station, and on one of my web pages, at there is a link that says 'Click HERE to listen' the 'HERE' contains a reference to either 1 of 2 pages.

When I put the radio station online, on Sun morning at 8:30am MST, I manually change the '<a href="">HERE</a>' to '<a href=" but when I go offline for routine maintenance on Thurs at 1:00pm, I manually change the '<a href=" to '<a href="no-online.htm">HERE</a>

You'll notice that there is only 1 link, and the word 'HERE' is not changed, just the reference. The script has to change this reference automatically, and still keep the same, link.

Below is the HTML code of the webpage that contains the 'HERE' link.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<title>60s British Rock in the USA</title>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Microsoft Theme" content="neon 111, default">
</head>

<body>
<p align="center"><!--webbot bot="Navigation" S-Type="banner"
S-Rendering="graphics" S-Orientation B-Include-Home B-Include-Up U-Page S-Target
-->
</p>
<hr align="center">
<p align="center"><font face="Academy Engraved LET" size="5" color="#00FF00"><a href="<hr align="center">
<p align="left"><font face="Arial" size="5">Welcome to my internet radio
station.</font></p>
<p align="left"><font face="Arial" size="5">I will only be up and running
between the hours of 8:30am MST (GMT +7 hrs) and 1pm MST, Sunday through
Thursday, the rest of the days, the station will be shut down for maintenance.</font></p>
<hr align="center">
<p align="left"><font face="Arial Narrow" color="#00FFFF" size="5">Music played
is from the early 60's through to the late 60' (some early 70's).</font></p>
<hr align="center">
<p align="center"><font size="5" face="Arial Narrow">&nbsp;<font face="Arial Narrow" size="6" color="#00FF00">Click
<a href="no-online.htm">HERE</a> to listen</font></font><font face="Arial Narrow" size="6" color="#00FF00">.</font></p>
<hr align="center">
</body>

</html>

Currently at the writing of this post, I have the '<a href="no-online.htm">HERE</a> changed, to the radio station reference.

Notice the link '<a href="no-online.htm">HERE</a> this is the link that has to stay, but the href content to be changed automatically to ' on a Sunday at 7:50am, it doesn't matter what the date is, as long as it's a sunday, then on a Thursday afternoon at 1:05pm the href content gets changed to 'no-online.htm', again, it doesn't matter what the date is, as long as it's a thursday.

I noticed in the script that it uses 'onlick', is that why 2 links have to used?, copy and paste the html code, and see if it can be modified to do as above.
 
>> The code is still using 2 links.

*groan*

Let me highlight this sentence from my first post again for you: I've given two links as an example. The one without the onclick event has no restrictions, but the other one will not function if you are within the restricted date/times.

The first link is an example. You can ignore it. Pretend I never put it on the page. Is was just to show that you can still have normal links on the page, as well as restricted links. I had thought that saying it was there as an example would have been stating the obvious, but I guess not.

To change the link that the user gets forwarded to during the "offline" period, you would change the link assignment in the last line of the alternateLink() function from ' to 'no-online.htm', and just make sure your link has the onclick event exactly as the [non-example] link in my last post did.

I hope this clarifies thinsg for you.

Dan
 

Thanks for the star! It was a very interesting script to write, and I enjoyed working on it. I have to admit, however, that ir was nowhere near as simple as I'd first thought (are they ever?! ;o)

I think that if it was between 2 set dates (for example, the 15th and 20th of the month), then it would definately have been a lot easier... But between any 2 days of the week, but with no specific date, proved interesting to calculate.

I have no idea if there are easier ways or not - there probably are many... So feel free to edit away ;o)

Dan
 
it still doesn't work, I tested it at 8:15am today and it still tries open the page to my radio station (which was offline) instead of opening the 'no-online.htm' page, below is the html code with the inserted script, I also noticed, that unless the code has changed in any way, IE always uses the page stored in the cache, thus resulting in the same page being used, therefore, the script will not work, regardless of day or time, unless the page is prevented from being cached.


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<title>Rock Radio</title>
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Microsoft Theme" content="neon 111, default">
<script type="text/javascript">
<!--
var startDay = 4; // Start Day: 0 - 6 (Sun = 0, Mon = 1 ... Fri = 5, Sat = 6)
var startHour = 13; // Start Hour: 0 - 23
var startMin = 5; // Start Min: 0 - 59
var endDay = 0; // End Day: 0 - 6 (Sun = 0, Mon = 1 ... Fri = 5, Sat = 6)
var endHour = 8; // End Hour: 0 - 23
var endMin = 25; // End Min: 0 - 59

function alternateLink(linkObj)
{
var startTimeDate = new Date(2004, 01, 01, startHour, startMin, 00);
with (startTimeDate) while (getDay() != startDay) setDate(getDate()+1);
var startTimeDateMsecs = startTimeDate.getTime();

var endTimeDate = new Date(2004, 01, 01, endHour, endMin-1, 00);
with (endTimeDate) while (getDate() < startTimeDate.getDate()) setDate(getDate()+1);
with (endTimeDate) while (getDay() != endDay) setDate(getDate()+1);
var endTimeDateMsecs = endTimeDate.getTime();

var now = new Date();
var currentTimeDate = new Date(2004, 01, 01, now.getHours(), now.getMinutes(), 00);
with (currentTimeDate) while (getDate() < startTimeDate.getDate()) setDate(getDate()+1);
with (currentTimeDate) while (getDay() != now.getDay()) setDate(getDate()+1);
var currentTimeDateMsecs = currentTimeDate.getTime();

if (currentTimeDateMsecs >= startTimeDateMsecs && currentTimeDateMsecs <= endTimeDateMsecs) linkObj.href = ' }
//-->
</script>
</head>

<body>
<p align="center"><!--webbot bot="Navigation" S-Type="banner"
S-Rendering="graphics" S-Orientation B-Include-Home B-Include-Up U-Page S-Target
-->
</p>
<hr align="center">
<p align="center"><font face="Academy Engraved LET" size="5" color="#00FF00"><a href="<hr align="center">
<p align="left"><font face="Arial" size="5">Welcome to my internet radio
station.</font></p>
<p align="left"><font face="Arial" size="5">I will only be up and running
between the hours of 8:30am MST (GMT +7 hrs) and 1pm MST, Sunday through
Thursday, the rest of the days, the station will be shut down for maintenance.</font></p>
<hr align="center">
<p align="left"><font face="Arial Narrow" color="#00FFFF" size="5">Music played
is from the early 60's through to the late 60' (some early 70's).</font></p>
<hr align="center">
<p align="center"><font size="5" face="Arial Narrow">&nbsp;<font face="Arial Narrow" size="6" color="#00FF00">Click
<a href=" onclick="alternateLink(this);">HERE</a> to listen</font></font><font face="Arial Narrow" size="6" color="#00FF00">.</font></p>
<hr align="center">
</body>

</html>

Perhaps this code could be modified so that the page can not be cached, and if I were to test it, on tuesday at 8:10am the 'no-online.htm' page would show, then test it again on tuesday at 8:35am the page to the radio station would open. The present code (above) doesn't work.

Then, when the above code is modified and working, I can copy and paste it back into the web page.

Oh yeah, and sorry about making someone *groan*. :) it's just that being a BASIC programmer, I'm trying to figure out the workings of javascript. I've tried using compiled BASIC for this, but there is no day function, only date$ which returns a 10 digit numeric date in the form mm-dd-yyyy.
 
The problem with doing the job in Javascript, surely, is that not only does it depend on the visitor having JS switched on, but it depends on them being in the same time zone as you are.

A server-side solution is better, if available. I don't really speak asp, but adapting jemminger's solution above, how about:
Code:
<%
    dim bOffline
    
    select case weekday(date())
        rem Su
        case 1
            bOffline = (hour() < 8)

        rem M, T, W
        case 2, 3, 4
            bOffline = false
            
        rem Th
        case 5
            bOffline = (time() >= timevalue("13:30:00"))
            
        rem F, Sa
        case 6, 7
            bOffline = true
    end select
    
    if bOffline
        response.write('<a href="offline.html">')
    else
        response.write('<a href="[URL unfurl="true"]http://rockradio.gotdns.org/radiophp/index.html">')[/URL]
    end if
%>
Click here</a>
In fact, you could use the same approach to either present a clickable link or a message saying the stations's off the air.

-- Chris Hunt
 
Chris there's a few little glitches in your code.
Code:
<%
    dim bOffline
    
    select case weekday(date())
        rem Su
        case 1
            bOffline = (hour() < 8)

        rem M, T, W
        case 2, 3, 4
            bOffline = false
            
        rem Th
        case 5
            bOffline = (time() >= timevalue("13:30:00"))
            
        rem F, Sa
        case 6, 7
            bOffline = true
    end select
    
    if bOffline then
        response.write [COLOR=red]"<a href=offline.html>"[/color]
    else
        response.write[COLOR=red]"<a href=[URL unfurl="true"]http://rockradio.gotdns.org/radiophp/index.html>"[/URL][/color]
    end if
%>
Click here</a>
The brackets aren't needed

Glen
 
The hosting server does not allow asp or php, I have to do everything in either html, java, or cgi.

Just incase anyone has tried the links in the html code, and wondered how I can use php, even though the hosting server does not allow its use.
When I'm online, I use a dynamic ip address to point to my IIS webserver which has the php pages.

At the moment, I'm working on a BASIC program to try and do the same thing, then, if it works, it'll be compiled into an exe file, then uploaded to the website, then using 'onload' the exe will be executed, checking the day and time (using time.windows.com so (hopefully)it wouldn't matter what time zone you're in), then it'll physically change the <a href></a> link at a preset time, if it works I'll post the link to where the exe can be downloaded, or I can post the raw program file in ascii.

I would rather like to use java though.

This should get some heads thinking.
Someone in an earlier post, said that the script would be affected by time zones, could the script be modified to access time.windows.com or to access the users time zone settings on their compter and convert to + or - hours, using MST as the base zone?

For example, if it's 8am MST and someone in the east of the USA, clicked on the link at 10am, then the script would convert that time by subtracting 2 hours, or someone clicked on the link in the UK, the script would subtract 7 hours, etc. etc. (also allowing for daylight saving time), then do the date/time check against the preset day(s) and time(s) and changing the link as needed.

Might be possible, but it's beyond me.
 
>> Someone in an earlier post, said that the script would be affected by time zones, could the script be modified to access time.windows.com or to access the users time zone settings on their compter and convert to + or - hours, using MST as the base zone?

See my previous message: Or you could convert all the date functions to use the UTC equivalents, maybe?

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top