Thursday, August 10, 2006

 

How to add a random quote generator

Here's some instructions to embed a random quote in the sidebar of your blogspot blog.
1) Edit the Template of your blog. Scroll down to just before the </head> tag and add:

<script type="text/javascript">
var usedNum = 0;
quotes = new Array;
quotes[1] = "Ma will save Taiwan";
quotes[2] = "Soong's a nice guy";
quotes[3] = "Lien Chan is competent";
quotes[4] = "Chen Shui-bian is popular";
quotes[5] = "Annette Lu doesn't want to become president";
quotes[6] = "Taiwan's politicians are uncorruptable";

function randomQuote() {
var rnum = 0;
var num = quotes.length - 1;
do {
var rval = Math.random();
rnum = Math.round((num - 1) * rval) + 1;
} while (rnum == usedNum);
usedNum = rnum;
var div = document.getElementById('quote-area');
div.innerHTML = quotes[usedNum];
}
</script>

2) A little further down change the <body> tag to this:
<body onLoad="randomQuote()">

3) Somewhere in your sidebar add the following:

<h6>Random Quote</h6>
<div id="quote-area"></div>

4) Edit the quotes, save the template then republish your blog.

If you have any problems, then try viewing source on this post to see how it works here ...

This page is powered by Blogger. Isn't yours?