Saturday, May 8, 2010

Quote of the day – Code in Javascript

Namaste,

I could not find quote of the day code which could support up to 365 quotes. So my friend J.M. developed a code. We re thank full to him for developing this code for free. We are happy to release Quote of the day code.

Features:

1. Quotes are parsed and so that no quote is missed.

2. Quotes refresh daily and not on browser tab refresh.

3. Upto 365 quotes. So new quote for a year.

4. Contains date script.

5. Fully customizable.

Troubleshooting / Points to consider while uploading the code.

1. Do not use special characters. They may / may not be supported.

2. Do not use the characters like Opening and closing double quotes (“ ”) and semicolon (;) since they are used by the codes.

e.g. if you use this quote

The Mother said, "She devotes her energy to bring up … passing through all these experiences; so then … done"

Then the code will look like

Quotes[1]= " The Mother said, "She devotes her energy to bring up … passing through all these experiences; so then … done" ";

a. As you can see there are two opening and two closing quotes.

b. Again the semi colon is repeated twice (one in the quote and another at the end (needed to complete the line of code)

This will not allow the code to work ad nothing will be displayed.

So change it to

Quotes[1]= " The Mother said, ‘She devotes her energy to bring up … passing through all these experiences, so then … done";

Here double opening and closing quotes (“”) are replaced by single ones (‘’) and semicolon (;) by comma (,).

The best and fastest way according to me is to copy the quotes in word processer like MS word. Then find and replace all ( “ ) by ( ‘), ( ” ) by ( ’) and ( ; ) by ( , ).

c. If the code is still not displayed, then remove other special characters like underscore (_), in short, make your quote in simple plain text and check if it works.

Please find code for Quote of the day.

Code:

<p><font face="Trebuchet MS" color="#800000" size="2">
<!-- date script starts -->
<div>
<script type="text/javascript">
var d=new Date()
var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
document.write(weekday[d.getDay()] + ", ")
document.write(monthname[d.getMonth()] + " ")
document.write(d.getDate() + " ")
document.write(d.getFullYear())
</script>
</div>

<!-- date script ends –>
<!— QOTD Script developed by J.M. for http://indiaspirituality.blogspot.com/ starts -->

<script type="text/javascript">
var today= new Date();
var first = new Date(today.getFullYear(), 0, 1);
var day = Math.round(((today - first) / 86400000), 0);
var numquotes = 5;
Quotes = new Array(numquotes+1);
Quotes[1]= " Once you know maya, it runs away, it can no more influence you.";
Quotes[2]= " Only god is truth, everything else is false";
Quotes[3]= " The one you has created the laws of nature also has the powers to change, replace or break the laws of nature";
Quotes[4]= " He who has faith has everything, and he who lacks faith lacks everything. It is the faith in the name of the Lord that works wonders, FAITH IS LIFE & DOUBT IS DEATH.";
Quotes[5]= " You can also ask for Brahma Jnana to divine mother.";
var ran = (day % numquotes) + 1;
document.write(Quotes[ran] + '<p style="text-align: right"><i>' +  '</i></p>');
</script>

</font></p>

<!-- end of OFTD script by J.M. -->
<p><font face="Trebuchet MS" color="#800000" size="2"><p><i>- Sri Ramakrishna</i></p></font></p>

 

How to use the code

1. The lines marked in green are the comments, which the makes no difference to a browser but makes it easier for us to identify the codes.

2.  The date script contains

("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

You can change ( Sunday ) to ( Sun ) and/or ( Jan ) to ( January )

If you do not wish to add date, then just delete lines starting from (including)

<!-- date script starts –>
to

<!-- date script ends –>


3. Change the number of quotes.

Find

var numquotes = 5;

change 5 to any number. here 5 is any number ‘n’

make sure that ‘n’ mentioned in var numquotes and the last number in square bracket after ( Quotes ) is the same.

Quotes[5]= " You can also ask for Brahma Jnana to divine mother.";

4.  I Have created the quote code which has only one saint. So Instead of adding the name in each quote I have added it in the last

<p><font face="Trebuchet MS" color="#800000" size="2"><p><i>- Sri Ramakrishna</i></p></font></p>

Here  ( – Sri Ramakrishna ) can be changed.

If you want to display quotes by more than one saints, then in each quote, the name has to be added manually.

e.g.

Quotes[5]= " You can also ask for Brahma Jnana to divine mother. – Sri Ramakrishna";

5. If you have some knowledge of CSS, then you can change way this script is displayed.

Hope you will find this script / code useful.

Hari Aum

INDIASPIRITUALITY

0 comments:

Post a Comment | Feed



 
^

Powered by BloggerINDIASPIRITUALITY Lite by UsuárioCompulsivo
original Washed Denim by Darren Delaye
Creative Commons License