Closed Thread Icon

Topic awaiting preservation: Randomising Bankground image Pages that link to <a href="https://ozoneasylum.com/backlink?for=21566" title="Pages that link to Topic awaiting preservation: Randomising Bankground image" rel="nofollow" >Topic awaiting preservation: Randomising Bankground image\

 
Author Thread
Blaise
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 04-27-2004 19:14

Hi guys, it's been a while how ya all doing?

I've got a little function that I use to randomise the background image of my body tag (using the class attribute), I've made it only work in IE6 and NS6, (browsers that recognise document.getElementById)

code:
function golgo13(){

if(document.getElementById){
siteBGs = new Array (
"alpha",
"lindisfarne",
"quran",
"stamp"
);

rando = Math.round( Math.random() * (siteBGs.length - 1) )
siteBG = siteBGs[rando];
document.body.className=siteBG;
}
}

This function is simply called with the onLoad event on the body tag,

What I would like to know is if there's a similar solution (ie an extension to the code already written) for making it work in earlier browsers, (yes unfortunatly I am talking about NS4).

Any comments will be greatly appreciated.

Cheers,

Blaise

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-27-2004 20:54

Blaise: Couldn't you use SSI or any server side language to set a random value to the class attribute of the BODY tag ?
Otherwise you could do something like :

code:
<html>
<head>

<style type="text/css">

p
{
margin:0;
}

</style>
<script type="text/javascript">

bodyClasses =
[
"background-color:orange; font-family:Georgia; color:white;",
"background-color:red; font-family:'Trebuchet ms'; color:pink;",
"background-color:navy; font-family:'Times New Roman'; color:gold;"
]

randomIndex = Math.floor( Math.random()*bodyClasses.length)
document.write( '<style type="text/css">body{'+ bodyClasses[randomIndex] +'}</style>' )

</script>

</head>
<body>

<h1>header</h1>
<p>lorem lipsum ...</p>

</body>
</html>

Ok it's slightly different from your initial approach, but it works from NN4.xx to FF0.8

Hope that helps,



(Edited by poi on 04-27-2004 11:56)

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 04-27-2004 20:58

That's definately the approach I would take, Poi.

You can still have an external stylesheet, including for the body, just use Javascript (or PHP, or whatever) to generate the background attributes for the body in the head of the document. No need to use a class or an id at all.

(Edited by DL-44 on 04-27-2004 11:59)

Blaise
Nervous Wreck (II) Inmate

From:
Insane since: Jun 2003

posted posted 04-28-2004 10:53

Well for starts I can't use server-side technology

But that's quite an interesting way around the problem, thanks for the tip, I don't really like using document.write in javaScript but I'll make an exception for this situation.

I quite liked my code I just wish it would work the same way in NS4 (or of course, that I didn't have to consider it at all!! )

Cheers!

Blaise

(Edited by Blaise on 04-28-2004 01:54)

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 04-28-2004 15:07
quote:
I'll make an exception for this situation.

The fact that you have to deal with NS4 at all is already an exception I'm afraid. It's like having to run a gas station and still having to have a hitching post, hay, and trough for the occasional horse.


. . : DHTML Slice Puzzle : . . . : Justice 4 Pat Richard : . .

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-28-2004 16:51
quote:
Bugimus said:

[...]The fact that you have to deal with NS4 at all is already an exception I'm afraid. [sic,...]


Well... you never worked with (some) government agencys ;-).
They sometimes have the oldest software... and I'm glad that I don't have to support Netscape 2.something in some projects.

mas
Paranoid (IV) Inmate

From: the space between us
Insane since: Sep 2002

posted posted 04-28-2004 17:44

you also could use something like mr max's sig rotator...i tried it out...it also works well

| - THESPACE - | E.A. | PORTFOLI0 | lonesome | CELL 557

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 04-28-2004 17:56

Blaise didn't mentioned what was in his classes, and more preciselly if there is something more than just a background image. And since he said he can't use server-side technology he'd have to host the random images on another host, which is rarely possible.

« BackwardsOnwards »

Show Forum Drop Down Menu