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

Time Related Hyperlinks 1

Status
Not open for further replies.

NoviceJavaUser

Programmer
May 19, 2004
10
GB
Hi,

Hope this is a simple answer.

Basically, i have 1 hyperlink, and dependant upon the time of day i want it to go to different pages, for example

between 0800 and 2100 hyperlink goes to page A
between 2101 and 0759 hyperlink goes to page B

Any ideas???
 
If you have a server side script then simply show the link based on the time - if not you can have a buffer page that is always linked to and based on finding the time with javascript location.replace() the correct page...

[conehead]
 
The problem with using client-side scripting to find the time is that the viewer's clock can be off. I worked on one computer where the clock was off by over a year, plus wrong day and wrong time of day. I discovered it when trying to update Norton virus definitions that they'd paid for online, and the key didn't work. I finally totally deleted Norton and reinstalled, and when I looked at how long the 1-year subscription was good for, the date was over 3 years in the future.

With Windows XP and the automatic update to the time enabled, that will become less and less of a problem as the older operating systems fall by the wayside.
 
>>Basically, i have 1 hyperlink, and dependant upon the time of day i want it to go to different pages,


sorry, u r depenedant on the user machine for this, or like cone said use server side programming...

Known is handfull, Unknown is worldfull
 
It has to be client side, and it is not a problem to use the Users PC's Time as it is a small business network that the web page will be located on, so not a problem with the system time being out.
 
Over the internet, you'd have to do it server-side - because it's a world-wide web, and when it's 21:00 for you it isn't necessarily the same time for me.

Since you're working on an intranet, you don;t have to worry about multiple timezones. You also don't have to worry about users having Javascript switched off or about accessibility to search engines.

You can therefore use Javascript to pick the page on the client side. It should be fairly simple. Something like this? ...
Code:
<script language="Javascript">
function pickpage () {
   var now = new Date();
   var time = (now.getHours() * 100) + now.getMinutes() ;
   var dest = "pageB.htm";
   if (time >= 800 && time <= 2100) dest="pageA.htm";
   window.location = dest;
}
</script>

<a href="javascript:pickpage()">Timed Link</a>

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
That is perfect Chris, just tested it and it works fine, to the second!! Many thanks to you all for your time and comments :)
 
AH!! Sorry... as an afterthought, i need different times of a weekend so for example Mon -Fri 0800 - 2100 Sat & Sun 1000 - 2000hrs
Is this anymore difficult? Sorry, i really am quite new to Java script :-(
 
For more javascript questions, please repost in Forum216, the javascript forum.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Chessbot's right, you should really be asking these questions in the Javascript forum. However, to keep the thread together, try this:
Code:
function pickpage () {
   var now = new Date();
   var time = (now.getHours() * 100) + now.getMinutes() ;
   var weekday = now.getDay();
   var dest = "pageB.htm";
   if (weekday > 0 && weekday < 6)  {
     if (time >= 800 && time <= 2100) dest="pageA.htm";
   } else {
     if (time >= 1000 && time <= 2000) dest="pageA.htm";
   }
   window.location = dest;
}

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top