| | |
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:
Solved Threads: 0
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
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
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:
JavaScript Syntax (Toggle Plain Text)
<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>
•
•
Join Date: Jan 2008
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
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:
JavaScript Syntax (Toggle Plain Text)
<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>
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....
JavaScript Syntax (Toggle Plain Text)
<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
Last edited by NancyNancyNancy; Apr 4th, 2008 at 11:52 pm.
•
•
Join Date: Jan 2008
Posts: 5
Reputation:
Solved Threads: 0
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
Nancy
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Hijackthis report, I just don't know (Viruses, Spyware and other Nasties)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: spry grow effect and gallery demo
- Next Thread: Page visibility using javascript
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column cookies createrange() css cursor dependent disablefirebug dom download dropdown editor element engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump libcurl math matrixcaptcha microsoft mimic object onerror onmouseoutdivproblem onreadystatechange parent pdf php player post problem progressbar rated rating regex runtime scroll search security select session shopping size software sql star stars synchronous text textarea unicode validation w3c web website window windowofwords windowsxp wysiwyg xml \n





