...

View Full Version : Javascript: How to HIDE a link at a certain time



xinzac
12-01-2009, 09:06 AM
Can anyone help? i'm trying to find some references and resources on how to hide a link at a certain time and show the link again at a certain time.

eg: from 12pm to 2pm the link will be display, users are able to click the link. after 2pm the link will not be displayed[hide] or the when click on the link error message will be shown. plz help. thanks!

VIPStephan
12-01-2009, 09:19 AM
You want references and resources? Well, a quick search brought http://www.w3schools.com/jsref/jsref_obj_date.asp. All you have to do now is use an if query and a little logic to use it for your needs. Something like:

Get current hour.
If current hour lower than your custom value show link
(else do something else)


Be aware that JS doesn’t necessarily have to be avaliable on all devices so think what should happen if it’s not before you use JS.

Philip M
12-01-2009, 10:00 AM
Here you are:-


<div id ="mylink" style="display:none" ><a href = "http://www.google.com">The link</a></div>

<script type = "text/javascript">

var now = new Date().getHours(); // current hour local time
if (now >=12 && now <=14) {
document.getElementById("mylink").style.display = "block";
}

</script>

But as remarked be aware that Javascript may not be available on all devices, or may be disabled. Also note that the times between which the link is displayed are referenced by the time as specified in the user's computer, that is local time.


Quizmaster: In Belgium, what Z is the name of a ferry port that's connected to the city of Bruges by a ship canal?
Contestant: Zurich.

manish_income
12-01-2009, 10:12 AM
Can anyone help? i'm trying to find some references and resources on how to hide a link at a certain time and show the link again at a certain time.

eg: from 12pm to 2pm the link will be display, users are able to click the link. after 2pm the link will not be displayed[hide] or the when click on the link error message will be shown. plz help. thanks!

<script language=javascript type='text/javascript'>
function hideDiv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideShow').style.visibility = 'hidden';
}
else {
if (document.layers) { // Netscape 4
document.hideShow.visibility = 'hidden';
}
else { // IE 4
document.all.hideShow.style.visibility = 'hidden';
}
}
}

function showDiv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideShow').style.visibility = 'visible';
}
else {
if (document.layers) { // Netscape 4
document.hideShow.visibility = 'visible';
}
else { // IE 4
document.all.hideShow.style.visibility = 'visible';
}
}
}
</script>

Philip M
12-01-2009, 11:53 AM
manish_income

This is simply rubbish, and does not in any way answer the question asked.
IE4 and Netscape4 are long obsolete. :mad:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum