PDA

View Full Version : questions about javascript banner rotator


morrisdan1
05-19-2005, 12:07 PM
Hi there,

How are you doing ? :smile:

I'd like to use the following javascript banner rotator codes throughout my site:

script language="JavaScript">
<!-- Begin
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
};

function rand(number) {
var result = Math.ceil(rnd()*number);
if (!result)result++;
return result
};
var ad_cnt1 = 2;
var ad1 = rand(ad_cnt1);
var link1;
var adBanner1;
var width1
var height1
if (ad1==1) {
link1="http://www.dansbanners.com";
adBanner1="http://www.dansbanners.com/images/banners/dansbanners.gif";
width1="468";
height1="60";
alt1="";
}
if (ad1==2) {
link1="http://www.dansbanners.com";
adBanner1="http://www.dansbanners.com/images/banners/dbanners.gif";
width1="468";
height1="60";
alt1="";
}
document.write('<center><a href="' + link1 + '" target="_new">');
document.write('<img src="' + adBanner1 + '" width=' + width1 + ' height=' + height1 + ' border=0 alt="' + alt1 + '"></a>');
document.write('</center>');
// End -->
</SCRIPT>

The only thing is that rather than using the above codes in each html page in my site, I rather copy the above script into one javascript file. And have all html files in my site point to it. That I know how to do so.

However, the part I need help with is what codes should I write in the html files that would implement the above script, if you know what I'm asking in here ? :umm:

Thanks again in advance! :yeah:

morrisdan1
05-20-2005, 11:39 AM
document.write('<center><a href="' + link1 + '" target="_new">');
document.write('<img src="' + adBanner1 + '" width=' + width1 + ' height=' + height1 + ' border=0 alt="' + alt1 + '"></a>');
document.write('</center>');


In another word, I think what I have to do is figure out how to write the above codes in html and insert those codes into the html files throughout my site. And have each html file point to that one same javascript file (ie. banner rotator javascript codes shown in 1st posting).

Can anyone help here ? :hrmm:

I'd appreciate it. Thanks in advance!

CDarklock
05-20-2005, 12:13 PM
In another word, I think what I have to do is figure out how to write the above codes in html and insert those codes into the html files throughout my site.

Nah, you just put the script tag wherever you want the banners to show up. Example:

// myscript.js

function TestJavaScript()
{
return "This is a test JavaScript function";
}
document.write(TestJavaScript());

Saved in same directory with this:

This is text;
<script src="myscript.js"></script>;
This is more text.

Gives us this result in a browser:

This is text; This is a test JavaScript function; This is more text.

Simple, ne c'est pas?