|
|
Forum moderator: bigblog |
uCoz Community For Webmasters Custom Solutions Greetings $code$ (Inquiry) |
Greetings $code$ |
Is there a code that will say "Good Morning" "Good Afternoon" "Good Evening" that depends on the time of the user?
Actually I needed this kind of code. I mean like this: $day$ = Tuesday If there isn't a code like this, is there a possibility that it will be implemented? 1F4BF3B
Post edited by Cyberdasm - Wednesday, 2016-10-19, 6:10 PM
|
Cyberdasm, you can do it with JavaScript:
Code <script type="text/javascript> currentTime = new Date(); if (currentTime.getHours() >= 6 && currentTime.getHours() <= 11 ) document.write("Good morning"); if (currentTime.getHours() >= 12 && currentTime.getHours() <= 17 ) document.write("Good afternoon"); if (currentTime.getHours() >= 18 && currentTime.getHours() <= 23) document.write("Good evening"); if (currentTime.getHours() >= 0 && currentTime.getHours() <= 5) document.write("You should go to sleep"); </script>! hey i'm joe and i do not work for the company anymore, please contact other staff or tech support
icon by ch-chau sometimes i lurk here |
bigblog, wherre do i install this exactly?..it does not display anything where i have put it!
Systems developer
|
Soldierdevil, that's weird. It should work literally everywhere where you can use HTML tags. Can you show me an URL of the page where you've inserted the code?
hey i'm joe and i do not work for the company anymore, please contact other staff or tech support
icon by ch-chau sometimes i lurk here |
Soldierdevil, you need to know first the Javascript DDS so that you could understand how it works. Yes i will say that I am confused at first how that code works since I am not familiar with javascript. But later on I figured it out. Here is the finished product.
The script doesn't have a call function make one then it works. Here's mine. My function Code <span id="demo"></span> My Script Code <script> currentTime = new Date, currentTime.getHours() >= 6 && currentTime.getHours() <= 11 && document.write("<span class='navbar-brand'><b>Good Morning, $USERNAME$</b></span>"), currentTime.getHours() >= 12 && currentTime.getHours() <= 17 && document.write("<span class='navbar-brand'><b>Good Afternoon, $USERNAME$</b></span>"), currentTime.getHours() >= 18 && currentTime.getHours() <= 23 && document.write("<span class='navbar-brand'><b>Good evening, $USERNAME$</b></span>"), currentTime.getHours() >= 0 && currentTime.getHours() <= 5 && document.write("<span class='navbar-brand'><b>You should go to sleep, $USERNAME$</b></span>"), document.getElementById("demo").innerHTML = x.write; </script> 1F4BF3B
Post edited by Cyberdasm - Monday, 2016-10-31, 3:01 AM
|
Cyberdasm,
Quote The script doesn't have a call function make one then it works. Systems developer
|
change the demo make it as what you want to call it.
document.getElementById("demo").innerHTML = x.write; Added (2016-10-31, 5:54 AM) --------------------------------------------- Its like this, post this code to where you want the "Good morning Mr. Blank" will be seen. <span id="editme"></span> usually the javascript is at the bottom of the page. paste this code there. Code <script> currentTime = new Date, currentTime.getHours() >= 6 && currentTime.getHours() <= 11 && document.write("<b>Good Morning, $USERNAME$</b>"), currentTime.getHours() >= 12 && currentTime.getHours() <= 17 && document.write("<b>Good Afternoon, $USERNAME$</b></span>"), currentTime.getHours() >= 18 && currentTime.getHours() <= 23 && document.write("<b>Good evening, $USERNAME$</b>"), currentTime.getHours() >= 0 && currentTime.getHours() <= 5 && document.write("<b>You should go to sleep, $USERNAME$</b>"), document.getElementById("editme").innerHTML = x.write; </script> 1F4BF3B
Post edited by Cyberdasm - Monday, 2016-10-31, 5:57 AM
|
Cyberdasm, thank you so much its working! I love you guys. Only that i wanna add on some images like a sine rise at good morning and also align all texts at the center of the page.
Systems developer
|
Soldierdevil, you can do that, too, but make sure you use apostrophes instead of quotation marks when they are needed.
hey i'm joe and i do not work for the company anymore, please contact other staff or tech support
icon by ch-chau sometimes i lurk here |
| |||
| |||