6 replies [Last post]
RideTheSpiral46
Offline
newbie
Last seen: 12 years 40 weeks ago
Joined: 2005-12-10
Posts: 5
Points: 0

I want to load one of 4 random stylesheets everytime someone visits my page...I've been putzing around with java for the past 3 hours with little success and I'm not sure my server space supports php (its university space) so if anyone has a script or can fix my java plz help

var style=Math.floor(Math.random()*5);

if (style=1) {
document.write('<link rel="stylesheet" href="css/burg.css" type="text/css">');
}
else if (style=2) {
document.write('<link rel="stylesheet" href="css/darkblue.css" type="text/css">');
}
else if (style=3) {
document.write('<link rel="stylesheet" href="css/lightblue.css" type="text/css">');
}
else {
document.write('<link rel="stylesheet" href="css/green.css" type="text/css">');
}// End -->*/

thanks,
Chris

Tags:
Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 6 years 4 hours ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Re: How can I load a random stylesheet

This works for me ...

<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>

Anonymous
Anonymous's picture
Guru

Re: How can I load a random stylesheet

RideTheSpiral46
Offline
newbie
Last seen: 12 years 40 weeks ago
Joined: 2005-12-10
Posts: 5
Points: 0

How can I load a random stylesheet

Thanks a ton, that worked perfectly....

Yeah I know my Java script is beyond terrible, I learned basic Java 3 years ago but never java script and I was trying to learn it last night at 4 in the morning, and I figured I'd include it just so it was easier to see what I was trying to do.

Thanks again,
Chris

RideTheSpiral46
Offline
newbie
Last seen: 12 years 40 weeks ago
Joined: 2005-12-10
Posts: 5
Points: 0

How can I load a random stylesheet

I finished the site (gotta write more content and fix up grammer) for the most part incase you want to see how I applied ur script.

http://phobos.ramapo.edu/~chdonnel/

Anonymous
Anonymous's picture
Guru

How can I load a random stylesheet

Nice. Laughing out loud

How about a nice slice of doctype pie? Try it. It's delicious.

wolfcry911
wolfcry911's picture
Offline
Guru
MA, USA
Last seen: 4 years 29 weeks ago
MA, USA
Timezone: GMT-5
Joined: 2004-09-01
Posts: 3224
Points: 237

How can I load a random stylesheet

that blue style has gotta go.