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

Recommended Answers

All 6 Replies

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:

<script type="text/javascript">
var display_date=new Date('04/04/2008');//this will be the date the link starts displaying
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
//get all dates in the same format
var current_date = new Date(month +'/' + day + '/' + year);
if(current_date>=display_date){
document.write('<a href="newlink.html">new link</a>');
}
</script>

Wow, thanks for the prompt response, BuddyLee17! I will give it a go. Much appreciated.

Nancy

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:

<script type="text/javascript">
var display_date=new Date('04/04/2008');//this will be the date the link starts displaying
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
//get all dates in the same format
var current_date = new Date(month +'/' + day + '/' + year);
if(current_date>=display_date){
document.write('<a href="newlink.html">new link</a>');
}
</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....

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

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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.