User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,769 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,202 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 952 | Replies: 6 | Solved
Reply
Join Date: Jan 2008
Posts: 5
Reputation: NancyNancyNancy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
NancyNancyNancy NancyNancyNancy is offline Offline
Newbie Poster

Code to control display of time-sensitive link?

  #1  
Apr 4th, 2008
I'm looking for a piece of code I used years ago to reveal a link at a later date. All I had to do was wrap the link in this piece of code and - presto - it revealed on the date and time that I wanted it to reveal.

I cannot remember if it was JavaScript or HTML. If you could offer any solutions I would be most grateful.

Thank you so much. I hope it's okay for me to cross-post in the HTML area.

Nancy
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 347
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 68
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Whiz

Re: Code to control display of time-sensitive link?

  #2  
Apr 4th, 2008
JavaScript will do this. HTML can't make decisions based on the date. A Server side script would be even better because the user can't disable it the way they can JavaScript. Anyway, here you go:
  1. <script type="text/javascript">
  2. var display_date=new Date('04/04/2008');//this will be the date the link starts displaying
  3. var currentTime = new Date();
  4. var month = currentTime.getMonth() + 1;
  5. var day = currentTime.getDate();
  6. var year = currentTime.getFullYear();
  7. //get all dates in the same format
  8. var current_date = new Date(month +'/' + day + '/' + year);
  9. if(current_date>=display_date){
  10. document.write('<a href="newlink.html">new link</a>');
  11. }
  12. </script>
Reply With Quote  
Join Date: Jan 2008
Posts: 5
Reputation: NancyNancyNancy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
NancyNancyNancy NancyNancyNancy is offline Offline
Newbie Poster

Re: Code to control display of time-sensitive link?

  #3  
Apr 4th, 2008
Wow, thanks for the prompt response, BuddyLee17! I will give it a go. Much appreciated.

Nancy
Reply With Quote  
Join Date: Jan 2008
Posts: 5
Reputation: NancyNancyNancy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
NancyNancyNancy NancyNancyNancy is offline Offline
Newbie Poster

Re: Code to control display of time-sensitive link?

  #4  
Apr 4th, 2008
Originally Posted by buddylee17 View Post
JavaScript will do this. HTML can't make decisions based on the date. A Server side script would be even better because the user can't disable it the way they can JavaScript. Anyway, here you go:
  1. <script type="text/javascript">
  2. var display_date=new Date('04/04/2008');//this will be the date the link starts displaying
  3. var currentTime = new Date();
  4. var month = currentTime.getMonth() + 1;
  5. var day = currentTime.getDate();
  6. var year = currentTime.getFullYear();
  7. //get all dates in the same format
  8. var current_date = new Date(month +'/' + day + '/' + year);
  9. if(current_date>=display_date){
  10. document.write('<a href="newlink.html">new link</a>');
  11. }
  12. </script>


Okay, I'm an idiot. Well, I guess 'newbie' is kinder.

I'm tinkering with your code... if I want something to display tomorrow, is this enough editing (below)? I could tinker better if I could do it by minutes instead of days because then I wouldn't have to wait very long to see if I made a mistake....

  1. <script type="text/javascript">
  2. var display_date=new Date('04/05/2008');//this will be the date the link starts displaying
  3. var currentTime = new Date('04/04/2008');
  4. var month = currentTime.getMonth();
  5. var day = currentTime.getDate() + 1;
  6. var year = currentTime.getFullYear();
  7. //get all dates in the same format
  8. var current_date = new Date(month +'/' + day + '/' + year);
  9. if(current_date>=display_date){
  10. document.write('<a href="http://www.whatever.com">Press Release</a>');
  11. }
  12. </script>

Sorry, not sure how many lines need editing. I changed the date to '+1' and removed same from the 'getMonth' line.

Thank you for your patience.

Nancy
Last edited by NancyNancyNancy : Apr 4th, 2008 at 10:52 pm.
Reply With Quote  
Join Date: Nov 2007
Location: Arkansas
Posts: 347
Reputation: buddylee17 will become famous soon enough buddylee17 will become famous soon enough 
Rep Power: 2
Solved Threads: 68
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Whiz

Re: Code to control display of time-sensitive link?

  #5  
Apr 4th, 2008
No, don't edit anything except for display_date on line 2 and link location in line 10. The rest of the script is how JavaScript reads the current date from your machine.
Reply With Quote  
Join Date: Jan 2008
Posts: 5
Reputation: NancyNancyNancy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
NancyNancyNancy NancyNancyNancy is offline Offline
Newbie Poster

Re: Code to control display of time-sensitive link?

  #6  
Apr 4th, 2008
THANKS!!! Glad you didn't have to take much time to correct my misunderstanding!! I was confused by "//get all dates in the same format"

Have a good night.
Nancy
Last edited by NancyNancyNancy : Apr 4th, 2008 at 11:17 pm.
Reply With Quote  
Join Date: Jan 2008
Posts: 5
Reputation: NancyNancyNancy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
NancyNancyNancy NancyNancyNancy is offline Offline
Newbie Poster

Re: Code to control display of time-sensitive link?

  #7  
Apr 22nd, 2008
I think I'll keep this thread open, because my question still involves 'code to control display of time-sensitive link'... now I would like to figure out how to HIDE a link at a certain time. Any suggestions greatly appreciated. And, if you would like, please feel free to refer me to any tutorials that you think would answer these types of questions. Thank you for your help, it's very kind of you.

Nancy
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC