3 replies [Last post]
randomguy132
randomguy132's picture
Offline
Enthusiast
NYC
Last seen: 15 years 23 weeks ago
NYC
Timezone: GMT-5
Joined: 2005-03-02
Posts: 69
Points: 0

What I want is essentially a: "Where am I right now?" section.
People will click on a link and depending on the day and time, it will take them to a different URL.

This sounds to me like JavaScript, but since I don't really know the language, I'm not sure.

What would be the best way to do this?

Tags:
antibland
antibland's picture
Offline
Leader
Pittsburgh
Last seen: 11 years 31 weeks ago
Pittsburgh
Joined: 2005-01-17
Posts: 603
Points: 0

Link points to different pages depending on time?

Here's something that works. It checks the hour of the day (1-24). It sets the href attribute of a give link n depending on that hour. For good measure, it sets the title attribute as well. Obviously, I didn't bother setting a behavior for every hour of the day. That's the fun part for you.Crying

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<script type="text/javascript">
var stamp = new Date();
var hour = stamp.getHours();
function setLink() {
	if (hour==1) {
		document.getElementById("link").setAttribute("href", "http://www.zeldman.com");
		document.getElementById("link").setAttribute("title", "zeldman's site");
	}
	else if (hour==22) {
		document.getElementById("link").setAttribute("href", "http://www.sony.com");
		document.getElementById("link").setAttribute("title", "cold-hearted bastards");
	}
}
window.onload = setLink;
</script>
</head>

<body>
<a id="link" href="http://www.somelink.com" title="some title">test link</a>
</body>
</html>

Cheers,

Gary...er...Andrew

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 12 hours 29 min ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9761
Points: 3843

Link points to different pages depending on time?

antibland wrote:

Cheers,

Gary...er...AndrewAre you making fun of me? Smile Nah, couldn't be. It must be someone else, I use all lowercase.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

antibland
antibland's picture
Offline
Leader
Pittsburgh
Last seen: 11 years 31 weeks ago
Pittsburgh
Joined: 2005-01-17
Posts: 603
Points: 0

Link points to different pages depending on time?

Now that I'm rooming with an English guy, the urge to write "cheers" is, at times, irresistible. Once "cheers" popped out of my head, writing "Gary" was also irresistible. So, I was referencing you, but only as a knee-jerk reaction to my geo-mental trappings.

Cheers,

gandrew (lowercase as it should be)