Sponsor for PC Pals Forum

Author Topic: Change font colour on page reload  (Read 3902 times)

Offline DJ

  • Established Member
  • ****
  • Posts: 1448
Change font colour on page reload
« on: February 17, 2007, 12:03 »
Hi

I want to automatically change a font colour when the web page reloads. So that each time you visit the page, the text is displayed in a different colour. There are only 6 colours that I want to use.

I have seen javascript to produce a random image on page reload, but not to change the font colour.

Anyone have any ideas?  The page is a very basic html page and only the heading needs to be changed.

Cheers

DJ

Offline sam

  • Administrator
  • *****
  • Posts: 19966
Re: Change font colour on page reload
« Reply #1 on: February 17, 2007, 13:36 »
i think something like this will do it


Code: [Select]
<script language="JavaScript">
<!--

if (top.frames.length > 0)
{
 top.location=self.location;
}


//color-picker:


function rnd(scale) {
var dd=new Date();
return((Math.round(Math.abs(Math.sin(dd.getTime()))*1000000000)%scale));
}


var bgc= new Array(15)
bgc[0] = "ffffff";  // white, pink, magenta
bgc[1] = "660066";  // purple, white, purple
bgc[2] = "000000";  // black, blue, cyan
bgc[3] = "006600";  // dark green, white, green
bgc[4] = "000000";  // black, cyan, turquoise
bgc[5] = "ccffff";  // turquoise, black, purple
bgc[6] = "ffcccc";  // pink, black, salmon
bgc[7] = "ff6666";  // salmon, dark red, red
bgc[8] = "66ff66";  // green, black, dark green
bgc[9] = "660099";  // violet, white, lilac
bgc[10] = "0066ff";  // blue, black, turquoise
bgc[11] = "00ccff";  // cyan, black, white
bgc[12] = "ffffff";  // white, violet, pink
bgc[13] = "ffff99";  // yellow, dark red, orange
bgc[14] = "cc33ff";  // lilac, purple, white
bgc[15] = "66ffcc";  // mint, dark green, green




var fgc= new Array(15)
fgc[0] = "ff00cc";
fgc[1] = "ffffff";
fgc[2] = "0000ff";
fgc[3] = "ffffff";
fgc[4] = "00ffff";
fgc[5] = "000000";
fgc[6] = "000000";
fgc[7] = "660000";
fgc[8] = "000000";
fgc[9] = "ffffff";
fgc[10] = "000000";
fgc[11] = "000000";
fgc[12] = "9900ff";
fgc[13] = "660000";
fgc[14] = "660066";
fgc[15] = "003300";


var lc= new Array(15)
lc[0] = "ff00ff";
lc[1] = "cc00cc";
lc[2] = "00ffff";
lc[3] = "00cc00";
lc[4] = "ccffff";
lc[5] = "9900ff";
lc[6] = "ff6666";
lc[7] = "cc3333";
lc[8] = "009900";
lc[9] = "cc99ff";
lc[10] = "ccffff";
lc[11] = "ffffff";
lc[12] = "ff00ff";
lc[13] = "ff9900";
lc[14] = "ffffff";
lc[15] = "009933";

var vlc= new Array(15)
vlc[0] = "ff00ff";
vlc[1] = "cc00cc";
vlc[2] = "00ffff";
vlc[3] = "00cc00";
vlc[4] = "ccffff";
vlc[5] = "9900ff";
vlc[6] = "ff6666";
vlc[7] = "cc3333";
vlc[8] = "009900";
vlc[9] = "cc99ff";
vlc[10] = "ccffff";
vlc[11] = "ffffff";
vlc[12] = "ff00ff";
vlc[13] = "ff9900";
vlc[14] = "ffffff";
vlc[15] = "009933";

var thing
thing=rnd(16);

function rc() {

document.bgColor="#"+bgc[thing];
document.fgColor="#"+fgc[thing];
document.linkColor="#"+lc[thing];
document.vlinkColor="#"+vlc[thing];
return thing;
}

// -->
</script>

<body onLoad="rc()" bgcolor="#660066" text="#ffffff" link="#cc00cc" alink="#000000" vlink="#cc00cc" marginheight="0" marginwidth="0" rightmargin="0" leftmargin="0" topmargin="0" bottommargin="0">
- sam | @starrydude --

Offline DJ

  • Established Member
  • ****
  • Posts: 1448
Re: Change font colour on page reload
« Reply #2 on: February 17, 2007, 14:49 »
Wow! thanks Sam :thumb:

Will have a play around with it and let you know how I get on.

Cheers  ;)

DJ

Offline Camstop

  • Loyal Member
  • *****
  • Posts: 4657
Re: Change font colour on page reload
« Reply #3 on: February 17, 2007, 17:39 »

Will have a play around with it and let you know how I get on.

Cheers  ;)

DJ


Too much info there DJ  :horror:

Offline DJ

  • Established Member
  • ****
  • Posts: 1448
Re: Change font colour on page reload
« Reply #4 on: February 18, 2007, 17:26 »
Too much info there DJ  :horror:

OK, been playing with it all weekend and its finally functioning correctly  :scratchit: :horror:

Cheers :thumb: Sam!!

DJ

Offline sam

  • Administrator
  • *****
  • Posts: 19966
Re: Change font colour on page reload
« Reply #5 on: February 18, 2007, 17:43 »
excellent, glad you got it working
- sam | @starrydude --


Show unread posts since last visit.
Sponsor for PC Pals Forum