...

View Full Version : is this easy to make ?



Fullwebservice
08-26-2002, 10:35 PM
I'm looking for a banner rotater of my own, in any lanugage, CGI/PHP/JAVA script...

i just need it to change banners if someone refreshes the screen, and then a new banner is there :)

also to be able to edit the size of the banner,


I dont knwo if this is easy or not to mak e,,


Thanks for your help :)

ConfusedOfLife
08-26-2002, 11:08 PM
Yeah! It's very easy! you have to make a random function that generates some numbers and based on those numbers, you can change your banners onload. let's say you have 3 images with the follwoing dimensions:


Name : Image1.jpg , Dim = 100px * 100px
Name : Image2.jpg , Dim = 132px * 58px
Name : Image3.jpg , Dim = 58px * 73px


we write:


<html>
<script>
function Init()
{
ourRand = Math.floor(Math.random() * 3);
switch ( ourRand )
{
case 0 :
document.getElementById('ourIMG').innerHTML =
"<img src='Image1.jpg' width='100' height='100'>";
case 1 :
document.getElementById('ourIMG').innerHTML =
"<img src='Image2.jpg' width='132' height='58'>";
case 2 :
document.getElementById('ourIMG').innerHTML =
"<img src='Image3.jpg' width='58' height='73'>";
}
}
</script>
<body onload = "Init()">
<div id="ourIMG">
&nbsp;
</div>
</body>




I didn't test what I wrote, but it has to work!

whammy
08-26-2002, 11:37 PM
That won't work cross-browser - but you can use the same kind of randomness to simply document.write a banner on the page each time.

Fullwebservice
08-28-2002, 05:55 PM
Thankx for the code.


whammy u said it work cross-browser , what do u mean by that ??

requestcode
08-28-2002, 06:16 PM
Here is a link to JavaScriptkits Free Script section and a Random Banner script:
http://www.wsabstract.com/script/cut149.shtml

This should work in all browsers. The previous script would only work in IE5 and NS6 and above.

ConfusedOfLife
08-28-2002, 11:56 PM
Just a question, you said that my code doesn't work in IE5- and NS6- and I admit, but just imagine that he/she wanted to write a code that changes an element of the page, let's say in a kinda period, WITHOUT reloading the whole page, what I'm asking is that is there a way to do this without using "innerHTML" or "nodeValue"? document.write works fine if you wana put something in the page and do not change it, but what if...

joh6nn
08-29-2002, 12:55 AM
you use the image.src and link.href properties. both are read/write. i've written this same kind of script, using both of those. my technique was to set up a 2d array of image urls and link urls, pick a random number, stick it in the array, and then use array[random][0] and array[random][1] to set the picture and link. if you do a search in the old forum, you'll find it once or twice.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum