Stylesheet Randomizer

Example:

This page uses the styleswap.js script with a few sample style-sheets from Dreamweaver. Reload this page to see a different stylesheet attached. Keep in mind that by sheer mathmatical odds, every now and then you might see the same stylesheet twice in a row.

How to use this script:

1) Download styleswap.js source code & save with your webpage:

// ---------------------------------------------------------------
// StyleSwap.js by Jessica Winblad
// A javascript library to swap out stylesheets at random
// ---------------------------------------------------------------

// modify this list to include the stylesheets you want to use
var itemList = new Array('style1.css', 'style2.css', 'style3.css', 'style4.css', 'style5.css');

var randomNum = Math.round(Math.random() * (itemList.length-1)+0);
var writestring = "<link href='" +itemList[randomNum]+ "' rel='stylesheet' type='text/css'>";
document.write(writestring);

2) Modify your webpage's HEAD section to reference the script:

<script src="styleswap.js" type="text/javascript"></script>
<noscript><link href="style1.css" rel="stylesheet" type="text/css"></noscript>

3) Modify the script/code to reference your stylesheets


More Web-Programming Resources