Click to See Complete Forum and Search --> : bgcolor randomizer


rosends
12-10-2002, 06:53 AM
Hi all -- I finally pieced together a script which randomizes the bgcolor and maintains contrast with the fgcolor but there is still one issue I need help on [and remember, I took code from here and there and have few brains, myself]. The code, as posted below, never returns a bgcolor in the red family. It used the time to set up a random scale function which creates the hex color, but it never seems to be in the red family. Could someone help me figure out why? Thans -- script follows:

<!-- Begin



function rnd(scale) {

// var dd=new Date();

// return((Math.round(Math.abs(Math.sin(dd.getTime()))*1000000000)%scale));
return (Math.floor(Math.random()*scale));
}




COLORCONSTANT = 16777215;
//backgroundColor = 256*rnd(255)+16*rnd(255)+rnd(255);
backgroundColor = (256*rnd(255)) + (16*rnd(255)) + (rnd(255));

document.bgColor = backgroundColor;
//document.fgColor=256*rnd(255)+256*rnd(255)+rnd(255);

forgroundColor = COLORCONSTANT - backgroundColor;
strFgColor = "000000" + forgroundColor.toString (16);
strFgColor = strFgColor.substr(strFgColor.length-6,6);
document.fgColor = strFgColor;

// End -->




Thanks again, Dan

rosends
12-12-2002, 01:57 PM
Thank you for the random stuff -- i see what you mean about randomness through that page...one other question.
i have read that IE5 and up don't allow for the find function, and yet the following worked:

alert(String("hello").find("o")

Someone put onto my color changing page a button which, when clicked, changes the web address to be the same thing, plus "?hc". he then inserted a conditional early on as follows:

if(String(document.location.href).find('?hc')!=-1) {
alert("true")
document.fgColor="black"
document.bgColor="white"


The point being, of course, that if the address is changed to include the ?hc, the colors would revert to simple black and white. I put an alert in to report back the String... and it shows up with the ?hc attached, but for some reason, the if..find isn't working.
Any ideas?
Thanks


by the way, the page is:

http://www.geocities.com/rosends//Homework_Hotline.html

rosends
12-13-2002, 06:59 AM
Did you ever have a situation where you swear something worked, but when you go and test it again, it didn't? So much for the find function.
I stuck randomizer in and used the same for the text color, ignoring contrast issues. What I have on the page is a button that should allow an individual, unhappy with the color scheme to revert to a black and white presentation. The button adds an ?hc to the address. What I need is a conditional check, at the top -- if the document name equals....?hc (where I type in the entire name plus the hc, then revert to black and white AND remove the ?hc from the name.

Can that be done as an out for those who hate fuschia on fuschia?

I have this page at http://www.geocities.com/rosends//hh2.html


also -- quick question -- is it possible to assign alink, link and vlink values to be equal to the fgcolor? I tried to but it didn't take.
Thanks for all the help -- Dan

rosends
12-13-2002, 07:45 AM
thanks -- that's perfect, but then I tried making a simple if statemet as follows:


var str = self.location.search.substr(1); alert(str);

if (str = "hc")
{
alert("true")
}

the true box comes up even when the alert(str) shows empty.

I'm sure that something is wrong with the syntax of the if statement, but I don't know what it is...thanks
D

rosends
12-13-2002, 09:51 AM
I finally got it to work by being incredibly concrete and non-portable. My only question pertains to the ability to assign alink, link and vlink values in the script. Thanks for all the help.
Dan