|
Answer» Hello Everyone,
Is it possible to display the email link on my website only at a certain time and remove it for the rest of the day automatically? Thanks a lot for any help..This is possible in two ways.
The best way would be to use a server-side programming language to determine whether you display the text or not.
Here's some dirty PHP you can drop right in an HTML file, assuming you have PHP on your server (only displays email between 2PM and 4PM, server time:
if( date('Gi', time()) > 1400 && date('Gi', time()) < 1600 ) { print "Your email address"; } ?>
The other way would be to do something similar with Javascript, but you would just hide or show the "email" element based on what time it is. The problem with the Javascript method is that you're only hiding/showing the element, or adding/removing the text. If a person was savvy and wanted your address, they could get it at any time by looking at the source code.
The first method, using server-side scripting, is the "safest."
-rockthanks a lot! I'll try the first ONE and will let you know then. Hi rockerest,
I pasted direcly the code you provided and it gave me this on the webpage:
1400 && date('Gi', time()) < 1600 ) { print "Email me "; } ?>
What's your thought on this? If you don't mind, can we also try the second one? It doesn't really matter if someone can see the email address by viewing the source code. As long as it's not seen on the webpage, that's good enough for me.
Thanks a lot! BTW, the code I pasted was this:
if( date('Gi', time()) > 1400 && date('Gi', time()) < 1600 ) { print "Email me "; } ?>
and it showed this on the webpage:
1400 && date('Gi', time()) < 1600 ) { print "Email me "; } ?>
you either didn't paste it into a PHP file or your server doesn't support PHP.
Quote from: BC_Programmer on January 20, 2011, 07:10:01 PM you either didn't paste it into a PHP file or your server doesn't support PHP.
Yes, I misspoke earlier when I SAID you could drop it in HTML. I always parse my HTML through a PHP framework, so I got lazy and didn't mention PHP.
You do need to make the page a .php file so that your server will interpret it through the PHP parser. You don't have to do anything special except rename the file from ".html" to ".php" If this still doesn't work, it's likely that your server doesn't support PHP, doesn't have it installed, or PHP is not running.
The javascript method would look something like this:
(HTML) Prints email between midnight and 1AM.
Code: [Select]<script type="text/javascript"> var time = new Date(); var hour = time.GetHours();
alert(hour); if( hour >= 0 && hour <= 1 ) { print "<span ID="email">[email protected]</span>"; } else { print "<span id="email">My email is unavailable.</span>"; } </script>
Full disclosure, I didn't test that code. But it, or something similar, should work.
-rockerest hello,
I created the file with exacly what you provided and loaded it into a browser, it's giving me a BLANK page. Any thoughts on this?
Mucho Gracias!
Quote from: rumejan on January 25, 2011, 01:11:02 PMMucho Gracias!
Muchas gracias
|