Forum Moderators: open
Suppose my image description is src="Directory/PictureName_small.JPG" and I want to redirect to www.google.com if the time is before 12, to www.lycos.com if between 12 and 18 hours and to www.yahoo.com otherwise, what is the code please?
Try this...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Link Changer</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<script type="text/javascript">
//<![CDATA[
function linkChange(){
var google='<a href="http://www.google.com/"><img src="your_image.jpg" alt=""/></a>';
var lycos='<a href="http://www.lycos.com/"><img src="your_image.jpg" alt=""/></a>';
var yahoo='<a href="http://www.yahoo.com/"><img src="your_image.jpg" alt=""/></a>';
var today=new Date();
var hour=today.getHours();if((hour>0) && (hour<=12)){
document.getElementById("foo").innerHTML=google;
}
else if((hour>12) && (hour<=18)){
document.getElementById("foo").innerHTML=lycos;
}
else if((hour>18) && (hour<=23)){
document.getElementById("foo").innerHTML=yahoo;
}
}
//]]>
</script>
</head>
<body onload="linkChange()">
<div id="foo">
</div>
</body>
</html>
;) ;)
birdbrain
You can't really use js to check to see if the user has js turned off, but you can use a combo of css and js to show/hide page elements--if js enabled, hide the jsDisabledDiv and show the jsEnabledDiv.
<script type="text/javascript">
<!--
//only fires if js enabled
function jsCheck(){
//hide jsDisabledDiv
document.getElementById('jsDisabledDiv').style.display="none"
//show jsEnabledDiv
document.getElementById('jsEnabledDiv').style.display="block"
}
//-->
</script>
<body onload="jsCheck()">
<!--jsDisabledDiv visible by default//-->
<div id="jsDisabledDiv">
blah...
</div>
<!--jsEnabledDiv hidden by default//-->
<div id="jsEnabledDiv" style="display:none">
blah...
</div>
ajkimoto