View Full Version : rotating layouts/ CSS sheets


NightHawk4900
01-24-2005, 03:27 AM
Okay... so on my xanga... (www.xanga.com/nighthawk4900) i succesfully used some javascript to randomly pick Page titles, splash page images, and status bar messages...

Then i got an idea to somehow use Javascript to randomly pic CSS sheets for my site so that when ppl look at it, it doesnt always look the exact same.... well i can get it to pick a CSS sheet and put it into a variable, but how can i use the variable in the

<link rel="stylesheet" href="link" type="text/css">

tag?

this is the code to randomly pick the sheet:

<script type='text/javascript'>

sheetx=new Array();
sheetx[0] = "http://home.comcast.net/~tphilip60/xanga.css";
sheetx[1] = "http://home.comcast.net/~tphilip60/xangablue.css";


var sheet = Math.floor(Math.random()*sheetx.length);

</script>

So to cap off, i need some way of USING the randomly picked CSS sheet on my site. Thanks in advance for any help...

wergo
01-24-2005, 11:58 AM
Maybe something like
document.write('<link rel=stylesheet type=text\/css href='+sheet+' \/>');

I'm not sure if that'll work. =/

NightHawk4900
01-25-2005, 08:47 PM
im srry, but that didnt work...

Monkey Bizzle
01-25-2005, 08:50 PM
try this:

http://www.alistapart.com/articles/alternate/

it is a script for a style switcher.

wergo
01-25-2005, 09:26 PM
I'm not getting anywhere with that link!

//edit
must be my connection right now. delete this if the above link works please :)

NightHawk4900
01-25-2005, 09:27 PM
try this:

http://www.alistapart.com/articles/alternate/

it is a script for a style switcher.
plus... i dont want to ask the person to select one... i just want them see a randomly picked one

NightHawk4900
01-28-2005, 03:20 AM
ok i got it guys... this is what i got to work... this all goes into the header section:


<link href="default.css" rel="stylesheet" type="text/css" id="styleSheet" />


<script type='text/javascript'>


sheetx=new Array();
sheetx[0] = "/xanga.css";
sheetx[1] = "/xangablue.css";


var sheet = Math.floor(Math.random()*sheetx.length);

var s = document.getElementById('styleSheet');
s.href = sheetx[sheet];


</script>

and yay! it worked