Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aaronw1986

macrumors 68030
Original poster
Oct 31, 2006
2,622
10
Hi all. I tried searching, but had trouble finding something relevant. How would I go about having different quotations (4-5) rotate which one is displayed on the main page of a site when it is loaded. The lower the language the better, is this possible with HTML/CSS? Any help would be greatly appreciated.
 
PHP out of the question ? or JavaScript ?

You could store the key of the last quotation displayed to the user in their cookie, or session details, and modify it every time they load the page.
 
Can't be done with HTML/CSS alone as they are not dynamic. You could use JavaScript or PHP. JavaScript is the lower of the levels, but requiring it will mean visitors who have JavaScript disabled (like me) won't see the quote, unless you have a default one in place. PHP would be seen by everyone though.

Here's the quick and dirty though in JavaScript. The same idea can be used in PHP if you want.

PHP:
var quotes = [
  "Hesitation kills!",
  "One is the loneliest number.",
  "With much money, comes great sadness."
];
var quote = Math.floor(quotes.length * Math.random());

function LoadQuote() {
  document.getElementById('quote').innerHTML = quotes[quote];
}
window.onload = LoadQuote;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.