Sunday, March 1, 2009

This code snippet will allow you to specify a random stylesheet to load.

Loading a random stylesheet allows you to specify a different look / feel / background / colour scheme for a visitor each time a page loads.

For the above reason, you should run at least two style sheets. One that contains the colour and picture information for your page elements, and another that controls the layout of your page.

Where you see Red, Blue, Green in the array, these are relative to the files Red.css, Blue.cc, and Green.css

<script>
function chooseStyle() {
var css = new Array('blue','red','green');
var i = Math.floor(Math.random()*css.length);
var style = "css/"+css[i]+".css";
return style;
}
document.write('<link rel="stylesheet" href="'+chooseStyle()+'" type="text/css">');
</script>