Forum Moderators: mack

Message Too Old, No Replies

Randomizing different versions of my site

         

Flagg6161

8:43 am on Sep 11, 2007 (gmt 0)

10+ Year Member



I have a site that I have created in 6 different color schemes (red.html, blue.html...). I want to write a redirect that will randomize between those 6 pages. So when someone visits my site, they first hit the index.html which is a redirector to one of the colors.html.

Can someone please help? My eyes are bleeding from searching.

MichaelBluejay

8:55 am on Sep 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Let me suggest better ways of doing what you're trying to accomplish other than a redirect.

The first is to have some Javascript code on your page that randomly picks one of six CSS stylesheets to use. You can probably find how to use Javascript to switch stylesheets with a Google search.

If you have only a couple of items to change, you could do that on the fly with Javascript, e.g.

<script type=text/javascript> 
colors = ['blue','red','green','yellow','orange','brown'];
x=Math.floor(Math.random()*6);
document.bgColor=colors[6];
</script>

Another option is to use server-side scripting to deliver a random CSS stylesheet. For example, using PHP, your page could have:

<?
(logic for selecting one of six lines that ultimately prints something like)

echo "<LINK rel=stylesheet type=text/css href=/css1.css>";
?>

If you really insist on using the redirect route, then you'd be looking at having some Javascript code that looks something like this:

<script type=text/javascript> 
x=Math.floor(Math.random()*6)+1;
window.location="index"+x+".html";
</script>

But this seems like a really bad practice. It's not good practice to ever take users to a page that they can't actually use. It's better practice to keep the user on the page they went to, and then fix up that page to display the way you want it to.

[edited by: MichaelBluejay at 9:02 am (utc) on Sep. 11, 2007]

Flagg6161

8:59 am on Sep 11, 2007 (gmt 0)

10+ Year Member



I have to be honest. I don't know anything about Javascript at all. Take a look at the different versions so you'll understand. I really appreciate your help.
<snip>

I just want to make it so that every visit or refresh pulls up one of those, randomly.

[edited by: engine at 9:42 am (utc) on Sep. 11, 2007]
[edit reason] See TOS [webmasterworld.com] [/edit]

MichaelBluejay

9:11 am on Sep 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm sorry, but since you're new here I guess you didn't know that links to our own sites aren't allowed. A moderator will come along and delete those soon, sorry.

But since I had a look at your site before the links were removed, I can see that none of the good suggestions I gave you will work, because your colors are generated by Flash. Most webmasters on this board don't like the use of Flash to generate all the content, because while Flash is very pretty, it's terrible for getting your site to rank well in the search engines. If that doesn't bother you, we can proceed on solving your issue. If it does bother you, then you'll need to consider re-doing your site without so much Flash.

The proper way to solve your issue if you want to keep the Flash is to have *Flash* pick the colors. Flash code is programming code, so just go to whoever developed your Flash for you, and tell them that you want it to pick one of six color schemes every time it loads. That's the proper way to do this.

I know you have your heart set on redirecting, but I promise you that's the wrong way to do it, as I mentioned in my first post. But if you really insist on doing it that way, then you can do it using a modified method I mentioned in that first post. I'll ask that you learn enough Javascript to do that yourself, rather than just handing you the complete code, because if you're going to go about this the wrong way, you should have the responsibility of writing that code yourself. :)

If you try to write your code and it doesn't work, then feel free to post about your troubles in the Javascript forum and people can help you there.

Flagg6161

5:45 pm on Sep 11, 2007 (gmt 0)

10+ Year Member



Sure. I understand. I am really not trying to get someone to write it for me. I would much rather be able to write it myself. The problem being that my site is actually a Flash template that I purchased and customized to suit our needs. I honestly don't even really know Flash at all. I know just enough to mess it all up. So I'm not able to go to the designer. And I'm not married to a redirection, it's just the first thought that I had. And the fact that I have to have my domain point to a specific file which is Index.html. But if I can have the index tell it which color to choose, that would work just fine. Thank you for all your help.

MichaelBluejay

9:31 am on Sep 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Since your site is in Flash, you can't use Javascript to change the colors on the page. You have four options as I see it:

(1) Use your redirection idea -- and learn enough Javascript to be able to code it yourself. It shouldn't take more than an hour or two.

(2) Hire a Flash developer to modify the code of your template. This is a good route because then you have only one url, not seven.

(3) Rename your page to <index.cgi> or <index.php>, where the file is either a Perl or a PHP script that randomly loads one of your six color schemes. This is another method that lets you have one url, not seven.

(4) Re-do the site without using Flash. Then you can use Javascript to set the colors.

Good luck!