Skip to content

Instantly share code, notes, and snippets.

@artlung
Created February 11, 2010 02:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save artlung/301130 to your computer and use it in GitHub Desktop.
Save artlung/301130 to your computer and use it in GitHub Desktop.
Load a random CSS file
<!-- this will print one of these:
<link rel="stylesheet" type="text/css" href="css/bk1.css" />
<link rel="stylesheet" type="text/css" href="css/bk2.css" />
<link rel="stylesheet" type="text/css" href="css/bk3.css" />
<link rel="stylesheet" type="text/css" href="css/bk4.css" />
<link rel="stylesheet" type="text/css" href="css/bk5.css" />
<link rel="stylesheet" type="text/css" href="css/bk6.css" /> -->
<script type="text/javascript" src="RANDOM_CSS_javascript.js"></script>
<script type="text/javascript">
RANDOM_CSS.printlinktag();
</script>
var RANDOM_CSS = {
cssfiles : ['bk1.css','bk2.css','bk3.css','bk4.css','bk5.css','bk6.css'],
pathtocss : 'css/',
getrandomcss : function() { return this.cssfiles[Math.floor(Math.random()*this.cssfiles.length)]; },
getlinktag : function() { return '<link rel="stylesheet" type="text/css" href="'+this.pathtocss+this.getrandomcss()+'" />'; },
printlinktag : function() { document.write(this.getlinktag()); }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment