Announcement

Collapse
No announcement yet.

JavaScript Question

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • JavaScript Question

    Before you flame me I've already spent a fair bit of time on google & experimenting, with no realy luck.

    Does anyone know how to select a CSS dynamically with JS?

    Basically I want the style of my site to change from day to day, inorder to mentain user interest.

    Rob
    And you say people actually pay money for M$ Windows?
    www.mp3mini.co.uk (Does what it says on the URL) www.openclassic.co.uk (The new car, with zero rust!) www.rob-web.co.uk (My other site)
    Total re-design underway: on the whole progress is very slow as the car is taking up too much time :)

  • #2
    Use something like this in your <head> section, remove the existing css reference first:


    <script language="javascript">
    var nRandomCSS = Math.floor(Math.random()*5);
    var sCSSFile = "";

    switch(nRandomCSS)
    {
    case 0: sCSSFile = "theme1.css"; break;
    case 1: sCSSFile = "theme2.css"; break;
    case 2: sCSSFile = "theme3.css"; break;
    case 3: sCSSFile = "theme4.css"; break;
    case 4: sCSSFile = "theme5.css"; break;
    }

    document.write("<link href=\"" + sCSSFile + "\" rel=\"stylesheet\" type=\"text/css\">");
    </script>
    VIA C3 800Mhz, 192Mb RAM, 10Gb 2.5" HDD, built-in video & audio, 7" Redant widescreen LCD, Win98Lite, Girder, GPS & street maps of Sydney & Melbourne.
    Spud's Carputer 3PM

    Comment


    • #3
      elligant solution spud...


      tho just using PHP would be alot easier...
      Project - GAME OVER :(

      Comment


      • #4
        Thanks alot, that's smashing.
        And you say people actually pay money for M$ Windows?
        www.mp3mini.co.uk (Does what it says on the URL) www.openclassic.co.uk (The new car, with zero rust!) www.rob-web.co.uk (My other site)
        Total re-design underway: on the whole progress is very slow as the car is taking up too much time :)

        Comment

        Working...
        X