Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Location
    singapore
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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!

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,666
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    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.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,986
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    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.

  • Users who have thanked Philip M for this post:

    xinzac (12-02-2009)

  • #4
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,986
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    manish_income

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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •