anti-keseronokan (old)
Fun Stuff for Anti-Fun People
This blog has moved to http://ikhwanhayat.net
Sunday, January 01, 2006
Random Subtitles
Can't make-up your mind on which subtitle to use for your blog? Have a list and felt that all of them seems cool? Why not use all! Utilising the random quote idea, we can use it for subtitles instead. What we want to do is to display different subtitles for each visit to our site. This is done via Javascript. What you need is to edit the blog template and put some codes inside. Add this at the very bottom of your page:
<script type="text/javascript">
function randomQuote(placeHolder) {
var ph = document.getElementById(placeHolder);
var quotes = new Array();
quotes.push("Writings from the coolest dude on the block.");
quotes.push("Cool people blogs.");
quotes.push("The epitome of coolness.");
quotes.push("Cooler than your average.");
var index = Math.floor(Math.random()*quotes.length);
ph.innerHTML = quotes[index];
}
randomQuote('subtitle');
</script>Change the text to your own cool and catchy subtitles. But if want to use mine, it's okay too :) Add more subtitles by repeating the quotes.push("new substitles"); line.
Then put this HTML tag at the place where you want it to display:
<span id="subtitle"
onclick="randomQuote('subtitle');"
style="cursor:pointer;"
title="Click here for random subtitles!">
</span>
This will act as the place holder for the random text. The important one is the "id" attribute. The code will use it to find where to put the text. If you don't want to use <SPAN>, you can use <DIV> instead, or maybe <H2>, or other tags that may satisfy your heart's desire. To add a nice touch to it, I put an onclick event handler that will re-generate the random quote, so you can click on the text to change it randomly. It's best if you have a long list. Because if your list is short, the random text generated might be the same as before, so it doesn't seem random enough.
Cool eh? But if you don't have lots of subtitles, or maybe you manage to find a really ultra cool subtitle that supersedes the others, this code might as well serve the original purpose as a random quote generator just as good.

2 Comments:
waa.. wtf, aku tak terpikir utk buat camtu..
Got the idea from QuirksMode. Original code taken from somewhere, tak ingatlah mana.. but i altered some part of it.
Post a Comment
<< Home