Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-01-2009, 09:06 AM   PM User | #1
xinzac
New to the CF scene

 
Join Date: Dec 2009
Location: singapore
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
xinzac is an unknown quantity at this point
Smile Javascript: How to HIDE a link at a certain time

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!
xinzac is offline   Reply With Quote
Old 12-01-2009, 09:19 AM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,601
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 12-01-2009, 10:00 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Here you are:-

Code:
<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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
xinzac (12-02-2009)
Old 12-01-2009, 10:12 AM   PM User | #4
manish_income
New to the CF scene

 
Join Date: Dec 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
manish_income can only hope to improve
Quote:
Originally Posted by xinzac View Post
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>
manish_income is offline   Reply With Quote
Old 12-01-2009, 11:53 AM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
manish_income

This is simply rubbish, and does not in any way answer the question asked.
IE4 and Netscape4 are long obsolete.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript link hide time

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:40 PM.


Advertisement
Log in to turn off these ads.