PDA

View Full Version : Why does this code work there but not here?


COOLORANGEFREEZ
09-03-2015, 10:13 PM
So I'm using the exact same code for rotating banners on my regular html cover page site (http://www.wartornnations.net/) and for my vBulletin 3.8.3 too (http://www.wartornnations.net/forum/).

It rotates just fine on the html site but it rotates sporadically only when I refresh the vBulletin site. What in the vBulletin code would hang up such a simple banner rotation code?

Any help is appreciated. The code follows:

HTML SITE CODE:

<html>
<head>
<title>www.wartornnations.net</title>
</head>
<body>
<DIV ALIGN=CENTER>
<script language="JavaScript">
<!--
function adArray() {
for (i=0; i*2<adArray.arguments.length; i++) {
this[i] = new Object();
this[i].src = adArray.arguments[i*2];
this[i].href = adArray.arguments[i*2+1];
}
this.length = i;
}
function getAdNum() {
dat = new Date();
dat = (dat.getTime()+"").charAt(8);
if (dat.length == 1)
ad_num = dat%ads.length;
else
ad_num = 0;
return ad_num;
}
var ads = new adArray(
"http://d2ysc6lw6qcd4g.cloudfront.net/728x90-proudly-support.jpg",
"http://www.woundedwarriorproject.org/",
"http://www.veteranscrisisline.net/banners/public/ads/VeteransCrisisLine-728x90-1-Static.gif",
"http://www.veteranscrisisline.net/"
);

var ad_num = getAdNum();

document.write('<table cellpadding=0 cellspacing=1 border=0><tr><td '
+'align="left">'
+'<A href="'+ads[ad_num].href+'"><IMG SRC="'+ads[ad_num].src+'" '
+'height="60" width="468" border="0" name="js_ad"></a></td></tr></table>');

link_num = document.links.length-1;

function rotateBanner() {
if (document.images) {
ad_num = (ad_num+1)%ads.length;
document.js_ad.src = ads[ad_num].src;
document.links[link_num].href = ads[ad_num].href;
setTimeout("rotateBanner()",5000);
}
}
setTimeout("rotateBanner()",5000);

// -->
</script>
</DIV>
</body>
</html>

VBULLETIN HEADER CODE:

<html>
<head>
<title>UKBL ~ 10 Second Banner Rotator</title>
</head>
<body>
<DIV ALIGN=CENTER>
<script language="JavaScript">
<!--
function adArray() {
for (i=0; i*2<adArray.arguments.length; i++) {
this[i] = new Object();
this[i].src = adArray.arguments[i*2];
this[i].href = adArray.arguments[i*2+1];
}
this.length = i;
}
function getAdNum() {
dat = new Date();
dat = (dat.getTime()+"").charAt(8);
if (dat.length == 1)
ad_num = dat%ads.length;
else
ad_num = 0;
return ad_num;
}
var ads = new adArray(
"http://d2ysc6lw6qcd4g.cloudfront.net/728x90-proudly-support.jpg",
"http://www.woundedwarriorproject.org/",
"http://www.veteranscrisisline.net/banners/public/ads/VeteransCrisisLine-728x90-1-Static.gif",
"http://www.veteranscrisisline.net/",
"http://firstrespondersomaha.org/wp-content/uploads/2015/03/TrueBlue-728x90.gif",
"http://firstrespondersomaha.org/support-blue-materials/"
);

var ad_num = getAdNum();

document.write('<table cellpadding=0 cellspacing=1 border=0><tr><td '
+'align="left">'
+'<A href="'+ads[ad_num].href+'"><IMG SRC="'+ads[ad_num].src+'" '
+'height="90" width="728" border="0" name="js_ad"></a></td></tr></table>');

link_num = document.links.length-1;

function rotateBanner() {
if (document.images) {
ad_num = (ad_num+1)%ads.length;
document.js_ad.src = ads[ad_num].src;
document.links[link_num].href = ads[ad_num].href;
setTimeout("rotateBanner()",5000);
}
}
setTimeout("rotateBanner()",5000);

// -->
</script>
</DIV>
</body>
</html>

Lynne
09-03-2015, 10:37 PM
You didn't add the <html> and <body> and <head> tags (and other tags that go with those) into the header, did you? You are going to break the html on your site if you don't just add the javascript for it into the header template.

COOLORANGEFREEZ
09-03-2015, 10:46 PM
I did add those.

I will take them out and reassess later this eve.

Thanks for the quick response.

Lynne
09-04-2015, 10:43 PM
After you change it, run the page through here and see if there are any errors related to any of the code you added - http://validator.w3.org/

COOLORANGEFREEZ
09-25-2015, 07:38 PM
Way overdue... thank you for your suggestion. It worked.