Old 08-25-2008   #1 (permalink)
L4A
Registered User
 

Join Date: Aug 2008
Posts: 4

Java Script Help (Banner Ad Rotator)

I was wondering if it would be possible to change the code of this script to miliseconds so more then 60 banners can be rotated (see script bellow).

<!-- Banner Ads Rotation Script -->
<!-- The JavaScript Source!! JavaScript Source: Free JavaScripts, Tutorials, Example Code, Reference, Resources, and Help -->
<!-- Adapted for www.thebookforum.com by Darren Lewis-->

<!-- Begin
var how_many_ads = 2;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==1) {
url="http://www.example1.htm";
alt="Example";
banner="http://www.example.com/example.gif";
width="468";
height="60";
}
if (ad==2) {
url="http://www.example1.htm";
alt="Example";
banner="http://www.example.com/example.gif";
width="468";
height="60";
}
// Output HTML code
document.write('<center>');
document.write('<a href=\"' + url + '\" target=\"_blank\">');
document.write('<img src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' ');
document.write('alt=\"' + alt + '\" border=0></a>');
document.write('</center>');
// End -->
L4A is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-25-2008   #2 (permalink)
Rusty Bio-Hazard!
 
notjustgraphics's Avatar
 

Join Date: Sep 2006
Location: Toronto, Ontario, Canada
Posts: 1,161
Images: 26

Send a message via MSN to notjustgraphics
Quote:
Originally Posted by L4A View Post
I was wondering if it would be possible to change the code of this script to miliseconds so more then 60 banners can be rotated (see script bellow).

<!-- Banner Ads Rotation Script -->
<!-- The JavaScript Source!! JavaScript Source: Free JavaScripts, Tutorials, Example Code, Reference, Resources, and Help -->
<!-- Adapted for www.thebookforum.com by Darren Lewis-->

<!-- Begin
var how_many_ads = 2;
var now = new Date()
var millisec = now.getMilliseconds()()
var ad = millisec % how_many_ads;
ad +=1;
if (ad==1) {
url="http://www.example1.htm";
alt="Example";
banner="http://www.example.com/example.gif";
width="468";
height="60";
}
if (ad==2) {
url="http://www.example1.htm";
alt="Example";
banner="http://www.example.com/example.gif";
width="468";
height="60";
}
// Output HTML code
document.write('<center>');
document.write('<a href=\"' + url + '\" target=\"_blank\">');
document.write('<img src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' ');
document.write('alt=\"' + alt + '\" border=0></a>');
document.write('</center>');
// End -->
Thats it.. pretty simple.. although I'm not sure exactly what your goal is.. There are better ways to do a simple banner rotation.

Cheers!
__________________
notjustgraphics is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-25-2008   #3 (permalink)
L4A
Registered User
 

Join Date: Aug 2008
Posts: 4

Thumbs up

Quote:
Originally Posted by notjustgraphics View Post
Thats it.. pretty simple.. although I'm not sure exactly what your goal is.. There are better ways to do a simple banner rotation.

Cheers!
Thanx so much for the info and the quick reply! I'll give it a try this evening.

As for my goal....

I've been using the aforementioned script for several years now. I've been using it to rotate banner ads on one of my message boards. The way the script is written (using seconds), I can rotate a total of up to 60 banners. If I try to ad 61, the 61st banner does not appear in the rotation. I figured by using miliseconds instead of seconds, I would be able to rotate 61, 70, 80, etc, etc, etc, banners.

I'll give it a try tonight. Thank you!!
L4A is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-25-2008   #4 (permalink)
Rusty Bio-Hazard!
 
notjustgraphics's Avatar
 

Join Date: Sep 2006
Location: Toronto, Ontario, Canada
Posts: 1,161
Images: 26

Send a message via MSN to notjustgraphics
<!-- Banner Ads Rotation Script -->
<!-- The JavaScript Source!! JavaScript Source: Free JavaScripts, Tutorials, Example Code, Reference, Resources, and Help -->
<!-- Adapted for www.thebookforum.com by Darren Lewis-->

<!-- Begin
var how_many_ads = 2;
var ad = Math.ceil(how_many_ads*Math.random());

if (ad==1) {
url="http://www.example1.htm";
alt="Example";
banner="http://www.example.com/example.gif";
width="468";
height="60";
}
if (ad==2) {
url="http://www.example1.htm";
alt="Example";
banner="http://www.example.com/example.gif";
width="468";
height="60";
}
// Output HTML code
document.write('<center>');
document.write('<a href=\"' + url + '\" target=\"_blank\">');
document.write('<img src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' ');
document.write('alt=\"' + alt + '\" border=0></a>');
document.write('</center>');
// End -->

The above code change (see red) would be my preferred method for executing a random selection.

It's effectively the same with a few less lines of code.

Both will work however.

Cheers!
__________________
notjustgraphics is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-25-2008   #5 (permalink)
L4A
Registered User
 

Join Date: Aug 2008
Posts: 4

Thumbs up

I like the "few less lines of code" thing!

psst...keep this between you and I. I'm a fisherman, not a programmer. So if I ask silly questions...

Silly Question #1 - If I use your example with the "fewer lines of code", will I be able to rotate an unlimited number of banners?

Thanx again for your prompt assistance! I really appreciate it!
L4A is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-25-2008   #6 (permalink)
Rusty Bio-Hazard!
 
notjustgraphics's Avatar
 

Join Date: Sep 2006
Location: Toronto, Ontario, Canada
Posts: 1,161
Images: 26

Send a message via MSN to notjustgraphics
Yes.. just change the first line to represent the total number of banners:

ie:

HTML Code:
var how_many_ads = 99;
Cheers!
__________________
notjustgraphics is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 08-26-2008   #7 (permalink)
L4A
Registered User
 

Join Date: Aug 2008
Posts: 4

Thank you NJG! I used the option your prefered -

<!-- Begin
var how_many_ads = 61;
var ad = Math.ceil(how_many_ads*Math.random());

and it worked perfectly

Thank you!!

p.s let me know if ya ever need help catching a fish
L4A is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning Java Script Help, Please! gradelover924 HTML / PHP / ASP / JS 3 12-29-2008 03:23 PM
Banner design fatih Adobe Photoshop 5 01-27-2007 10:56 PM
Banner Tutorial Shantih_11 Adobe Photoshop 10 11-05-2006 09:00 PM
random banner ad's script supafly HTML / PHP / ASP / JS 6 10-08-2006 08:21 PM
A wrestling banner T_Immy Showrooms & Works In Progress 6 01-11-2006 03:24 AM


All times are GMT +1. The time now is 04:43 AM.

Powered by vBulletin Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT