Click to See Complete Forum and Search --> : Help? Wanna change bg color on the fly...


robio
05-04-2003, 06:41 PM
Can anyone tell me how I can make the background color of a page change depending on where it's loading from?

I'm working on a possible site redesign that may include pages that look like this:
http://splicedwire.com/CENTER_PROJECT/SUPERBANNER_lizzie.html

But I have client sites with different color schemes that pull my pages into framesets, so I'd like to be able to make that oh-so-RED background (which clashes with everything in the world not on SPLICEDwire.com) change into other colors on the fly.

I've found javascript bg color randomizers on the web, but I can't find anything to say"if the user is within frameset XX, make bg color YYY".

Any help would be appreciated.

:)
Rob
SPLICEDwire

brendandonhue
05-04-2003, 07:36 PM
<script language="javascript">
var url = parent.document.location;

if (url=="http://something.com")
{document.bgColor = "red"}

if (url=="http://somethingelse.com")
{document.bgColor = "blue"}


else
{document.bgColor = "white"}
</script>

brendandonhue
05-05-2003, 06:33 AM
You might want to try using Query Strings, to make changing colors easier for your clients.
That way, into their frame they would load.

Yoursite.com/page.html?background=blue
and a script on page.html would pull the color out, and use it as the background.

robio
05-06-2003, 05:42 AM
Originally posted by brendandonhue
You might want to try using Query Strings, to make changing colors easier for your clients.
That way, into their frame they would load.

Yoursite.com/page.html?background=blue
and a script on page.html would pull the color out, and use it as the background.

Thanks for both suggestions.

I'm afraid I'm not java-savvy and don't know how do do this one (i.e. I don't know how to write a script on page.html that would pull the color out). If it's something that's easily explained (or copied), I'd appreciate knowing more.

Thanks again,
:)
Rob

AdamGundry
05-06-2003, 10:20 AM
You can use this script (http://www.agbs.co.uk/scripts/get_extract.html) to turn the background=whatever GET variable into a Javascript variable.

You can then use code like the following:
<script type="text/javascript">
document.bgColor = background;
</script>

Adam

robio
05-07-2003, 04:55 AM
Thanks!This sounds great, but I'm a little green so I'm not quite clear what I'm doing with all this. I know where to stick the script to get the variable bgcolor, but what code do I use on the page the client is linking from?

:)
Rob

AdamGundry
05-07-2003, 10:47 AM
Use a hyperlink like this:

<a href="http://www.example.com/page.html?background=blue">Blue Background page</a>

The important bit is the "?background=blue", which will be parsed by the script into a JS variable called background with the value "blue", which can then be set using the code above.

Change the text after the equals sign to change the resulting colour.

Adam

robio
05-08-2003, 04:57 AM
Thanks so much! I'm gonna give it a try.

:)
Rob