Code to control display of time-sensitive link?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jan 2008
Posts: 5
Reputation: NancyNancyNancy is an unknown quantity at this point 
Solved Threads: 0
NancyNancyNancy NancyNancyNancy is offline Offline
Newbie Poster

Code to control display of time-sensitive link?

 
0
  #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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

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

 
0
  #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 Quick reply to this message  
Join Date: Jan 2008
Posts: 5
Reputation: NancyNancyNancy is an unknown quantity at this point 
Solved Threads: 0
NancyNancyNancy NancyNancyNancy is offline Offline
Newbie Poster

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

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

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

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

 
0
  #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 11:52 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

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

 
0
  #5
Apr 5th, 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 Quick reply to this message  
Join Date: Jan 2008
Posts: 5
Reputation: NancyNancyNancy is an unknown quantity at this point 
Solved Threads: 0
NancyNancyNancy NancyNancyNancy is offline Offline
Newbie Poster

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

 
0
  #6
Apr 5th, 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 5th, 2008 at 12:17 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 5
Reputation: NancyNancyNancy is an unknown quantity at this point 
Solved Threads: 0
NancyNancyNancy NancyNancyNancy is offline Offline
Newbie Poster

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

 
0
  #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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC