tips and tricks for movable type

random page titles
September 21, 2002

In this support forum thread, Mikerzz needed help with a piece of Javascript that creates random page titles for your HTML document. Once we made it work, I decided it was worth blogging the little script!

<title><dummy title></title>
<script TYPE="text/javascript" LANGUAGE="JavaScript">
<!--//

if (parseInt(navigator.appVersion) >= 4) {
var num = 5;
var ttl = new Array(num+1);
ttl[1] = "I love Brad Pitt!";
ttl[2] = "I love Mark Wahlberg!";
ttl[3] = "I love Chris Cagle!";
ttl[4] = "I love Movable Type!";
ttl[5] = "I love Learning New S**t!";
ranNumber = parseInt(num * Math.random() + 1);
document.title = ttl[ranNumber];
}

//-->
</script>

The script has to be between your <title> and </head> tags. Change the 5 to match the number of random titles you're using.

(This script originally contained a credit to semistatic.com, but when I visited that URL, it appeared to be a dead domain. The only other site I found using it was written in Spanish, so I don't really know who deserves the acknowledgement for it.)

Comments

Wouldn't it be possible to include the java script in a template module, then call it to where ever you wanted? That's what I did with my QOTD script. Might work and let you put random info anywhere you want. Will give a go and report back this evening.

by Larry | 07.04.03 10:22 AM

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

TrackBack: 1
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/87)

» That Was Fun
Excerpt: Well, as mentioned, I've been tinkering around the Snakepit. It keeps me amused. Truth is, it was quite fun but a lot more work than I expected. I installed a rotating title bar, an idea that I picked up from Joni Electric, who always has the most cool...
Weblog: Electric Venom
Tracked: 04.12.03 05:55 AM