You're not a programmer but you have a website. Would you like to add some
In case you're wondering if you need anything special to run
I am not trying to teach you
Display today's date
You can use this
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var d = new Date();
var weekDay = days[d.getDay()];
var month = months[d.getMonth()];
var day = d.getDate();
var year = d.getYear();
var suffix = 'th';
if (day == 1) suffix = 'st';
else if (day == 2) suffix = 'nd';
else if (day == 3) suffix = 'rd';
document.write(weekDay+', '+month+' '+day+suffix+', '+year);
This piece of code will display the date in this format: Monday, April 3rd, 2006 . If your site is in a language other than english, just replace the days and months names. You can replace the suffix letters so they don't get displayed either, by changing 'th' to '', 'st' to '', 'nd' to '' and 'rd' to ''. If you want to change how the date is displayed, to make it look like this, for example: Monday, 3 April 2006 , you need to move things around a little in the document.write line. This is how the document.write line should look to display the date in the format I just mentioned:
document.write(weekDay+', '+day+' '+month+' '+year);
You can notice we have removed the suffix part here.
If you're wondering why would you like to display today's date in the page, the answer I give you is: to provide your visitors the impression that your page is updated very often. That the page is up-to-date. Anyway, I think it is a nice touch.
Display a message in the status bar
You can use this small bit of
window.status = 'This is my message.';
Paste this piece of code somewhere in the body of your page, and replace the This is my message text with the message you want to show.
You can combine both pieces of code and display today's date on the status bar if you wish. Just use the code piece to display the date, and replace
document.write(weekDay+', '+month+' '+day+suffix+', '+year);
with
window.status = weekDay+', '+month+' '+day+suffix+', '+year;
There is much more you can do with
Source by Sergio Roth
Post a Comment