Results 1 to 4 of 4

Thread: JavaScript Question

  1. #1
    Rob
    Rob is offline
    Maximum Bitrate Rob's Avatar
    Join Date
    Aug 2001
    Location
    Missing In Action
    Posts
    779

    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. #2
    Newbie
    Join Date
    Dec 2001
    Location
    Sydney, Australia
    Posts
    42
    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

  3. #3
    FLAC
    Join Date
    Apr 2001
    Location
    Here, There, Everywhere
    Posts
    1,436
    elligant solution spud...


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

  4. #4
    Rob
    Rob is offline
    Maximum Bitrate Rob's Avatar
    Join Date
    Aug 2001
    Location
    Missing In Action
    Posts
    779
    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 :)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •