Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Smile Randomly Rotating Websites

    This might be a crazy question, but maybe someone here has an answer...

    I am building a site and have proposed three layouts to my client. He said he loves all three and cannot choose between them. He came up with the idea that we use all of them, and each time a user goes to the URL, they are directed at random to a different layout.

    I have done this in the past with randomly rotating images - but is it possible to do it with the ENTIRE site? Any links with info on this?

    Thanks!

    -Sophie

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    I'm guessing you're using different CSS stylesheets for templates. In which case you'd be using the following function:

    Code:
    <script type="text/javascript">
    function setActiveStyleSheet() {
        var title = Math.floor(Math.random()*3);
        var i, a, main;
        for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
            if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
                a.disabled = true;
                if(a.getAttribute("title") == title) 
                    a.disabled = false;
         }
       }
    }
    window.onload = setActiveStyleSheet;
    </script>
    And of course, you'd add the different stylesheets like so:

    Code:
    <link rel="alternate stylesheet" type="text/css" href="1.css" title="0" />
    <link rel="alternate stylesheet" type="text/css" href="2.css" title="1" />
    <link rel="alternate stylesheet" type="text/css" href="3.css" title="2" />
    The title is the important attribute, because that's what the function uses to determine which stylesheet to use on this occurance. It is a random generation, though considering we're working only with 3 numbers, you might get to see plenty of repetitions. I also am not entirely sure exactly why someone would want to use three different randomly selected templates for a serious website, due to it being confusing to users who visit more than once, but... that's just my point of view, I guess. Enjoy.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Location
    Tannhäuser Gate
    Posts
    286
    Thanks
    7
    Thanked 58 Times in 57 Posts
    You can check out this site - quite well known example of that ''crazy'' idea.

    And this article should be enough to add some persistence, if you wish so. Because what Eldarrion said about annoying returning customers is a valid point.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    You can set up a default start page and then redirect as follows:- (this is based on your request for a different layout for the entire site, not just one page):-

    Code:
    <body onload = "selectSite()">
    
    <script type = "text/javascript">
    
    function selectSite() {
    var theSite = new Array("http://www.siteOne.com","http://www.siteTwo.com","http://:www.siteThree.com");
    var x = Math.floor(Math.random() * 3);  // random 0-2
    window.location = theSite[x];
    }
    
    </script>
    or of course use siteOne.com as the base page and redirect to another page if the random number is 1 or 2.

    Code:
    if (x > 0) {
    window.location = theSite[x];
    }
    Quote Originally Posted by Eldarrion View Post
    I also am not entirely sure exactly why someone would want to use three different randomly selected templates for a serious website, due to it being confusing to users who visit more than once, but... that's just my point of view, I guess.
    - I agree with this.



    Quizmaster: The Cairngorm Mountains are home to Britain's last free-ranging herds of which animals, popularly associated with Christmas?
    Contestant: Turkeys.
    Last edited by Philip M; 03-13-2009 at 08:03 PM.

  • #5
    New Coder
    Join Date
    Nov 2008
    Posts
    33
    Thanks
    5
    Thanked 0 Times in 0 Posts
    thanks philip - i think this is exactly what i am looking for. as for the problem with it being inconsistent, i tend to agree, however this is just a portfolio page for an artist so i think the effect could be fun. thanks again!


  •  

    Posting Permissions

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