educational

Banner Rotation Using JavaScript

One of the most welcome "newbie" applications for JavaScript is as a means of banner rotation. While the more experienced Webmaster may shun such an application in favor of much more robust CGI/Perl, PHP, or other suitable technologies, these are often beyond the newbie's grasp (and budget), and likely not possible with most free hosted Web accounts. Here are three good examples of banner rotation using JavaScript:

BANNER ROTATOR #1
This script shows a random banner or other image along with a hyperlink and text description. This script is easily customizable for your page; simply change the linking urls, image urls, and the link names that you wish to display (be sure the order matches) and ensure that the last one of each type does not contain a comma (,) at the end.

<SCRIPT language="JavaScript">
<!-- BANNER ROTATOR #1

var currentdate = 0;
var core = 0;

This "weighted" rotation script not only displays your banners, but also controls how often they appear, allowing you to display a preferred banner over any others!

function initArray() {

this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}

link = new initArray(
"https://URL 1/",
"https://URL 2/",
"https://URL 3/"
);

image = new initArray(
"https://IMAGE 1.gif",
"https://IMAGE 2.gif",
"https://IMAGE 3.gif"
);

text = new initArray(
"DESCRIPTION 1",
"DESCRIPTION 2",
"DESCRIPTION 3"
);

var currentdate = new Date();
var core = currentdate.getSeconds() % image.length;
var ranlink = link[core];
var ranimage = image[core];
var rantext = text[core];

document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');

// BANNER ROTATOR #1 -->
</SCRIPT>

BANNER ROTATOR #2
This hot script will change banner images on the fly, with no need to reload the page! You can also adjust the amount of time that each banner is shown!

Place the following lines inside of your <HEAD></HEAD> tag:

<SCRIPT language="JavaScript">
<!-- BANNER ROTATOR #2
var mfBanners = [
['https://www.URL 1.com', 'https://BANNER 1.gif'],
['https://www.URL 2.com', 'https://BANNER 2.gif'],
['https://www.URL 3.com', 'https://BANNER 3.gif']
];
var mfIe = false;
if( document.all) {
mfIe = true;
}
var mfBannerIndex = 0;
function mfBannerChange() {
var htmlString = '<a target="_blank" href="'+mfBanners[mfBannerIndex][0]+'"> <img border="0" src="'+mfBanners[mfBannerIndex][1]+'"></a>';
if( mfIe) {
document.all.banner.innerHTML = htmlString;
}
else {
document.layers["banner"].document.open();
document.layers["banner"].document.write( htmlString);
document.layers["banner"].document.close();
}
if(mfBannerIndex < mfBanners.length - 1)
mfBannerIndex++;
else
mfBannerIndex = 0;
}
setInterval("mfBannerChange()", 5000);
// BANNER ROTATOR #2 -->
</SCRIPT>

Now put the following lines inside of your <BODY> code:

<DIV id="banner" style="position:absolute; top:300; left:171;"></DIV>

BANNER ROTATOR #3
This "weighted" rotation script not only displays your banners, but also controls how often they appear, allowing you to display a preferred banner over any others!

Place the following lines inside of your <HEAD></HEAD> tag:

<SCRIPT language="JavaScript">
<!-- BANNER ROTATOR #3
function banner(imgSource,url,alt,chance) {
this.imgSource = imgSource;
this.url = url;
this.alt = alt;
this.chance = chance;
}
function dispBanner() {
with (this) document.write("<A HREF=" + url + "><IMG SRC='" + imgSource + "' WIDTH=468 HEIGHT=60 BORDER=0 ALT='" + alt + "'></A>");
}
banner.prototype.dispBanner = dispBanner;
banners = new Array();
banners[0] = new banner("https://www.BANNER 1.jpg",
"https://www.URL 1.net target='_blank'",
"DESCRIPTION 1",
10);
banners[1] = new banner("https://BANNER 2.gif",
"https://www.URL 2.com target='_blank'",
"DESCRIPTION 2",
30);
banners[2] = new banner("https://BANNER 3.gif",
"https://www.URL 3.com target='_blank'",
"DESCRIPTION 3",
20);

///////////////////////////////////////////////////
// banners[x] = new banner(<banner source image>, // <url to link to when the banner is clicked>, // <alt> // <the chance this banner has in which to be randomly selected>);
// To increase the chance of a banner being randomly selected, increase it's corresponding // 'chance' property relative to the other banners.
///////////////////////////////////////////////////

sum_of_all_chances = 0;
for (i = 0; i < banners.length; i++) {
sum_of_all_chances += banners[i].chance;
}
function randomBanner() {
chance_limit = 0;
randomly_selected_chance = Math.round((sum_of_all_chances - 1) * Math.random()) + 1;
for (i = 0; i < banners.length; i++) {
chance_limit += banners[i].chance;
if (randomly_selected_chance <= chance_limit) {
document.write("<A HREF=" + banners[i].url + "><IMG SRC='" + banners[i].imgSource + "' WIDTH=468 HEIGHT=60 BORDER=0 ALT='" + banners[i].alt + "'></A>");
return banners[i];
break;
}
}
}
// BANNER ROTATOR #3 -->
</SCRIPT>

Hopefully one of these JavaScripts will allow you to maximize your advertising effectiveness by presenting a variety of banners to your site's visitors. Measuring which of several banners produces the best results will alow you to tailor your ad approach to your audience. Good Luck!

Copyright © 2025 Adnet Media. All Rights Reserved. XBIZ is a trademark of Adnet Media.
Reproduction in whole or in part in any form or medium without express written permission is prohibited.

More Articles

profile

WIA Profile: Leah Koons

If you’ve been to an industry event lately, odds are you’ve heard Leah Koons even before you’ve seen her. As Fansly’s director of marketing, Koons helps steer one of the fastest-growing creator platforms on the web.

Women in Adult ·
opinion

What France's New Law Means for Age Verification Worldwide

When France implemented its Security and Regulation of the Digital Space (SREN) law on April 11, it marked a pivotal moment in the ongoing global debate surrounding online safety and access to adult content.

Corey D. Silverstein ·
opinion

From Tariffs to Trends: Staying Resilient in a Shaky Online Adult Market

Whenever I check in with clients these days, I encounter the same concerns. For many, business has not quite bounced back after the typical post-holiday-season slowdown. Instead, consumers have been holding back due to the economic uncertainty around the Trump administration’s new tariffs and their impact on prices.

Cathy Beardsley ·
opinion

Optimizing Payment Strategies for High Ticket Sales

Payment processing for more expensive items, such as those exceeding $1,000 per order, can create unique challenges. For adult businesses, those challenges are magnified. Increased fraud risk, elevated chargeback ratios and heavier scrutiny from banks and processors are only the beginning.

Jonathan Corona ·
profile

WIA Profile: Lexi Morin

Lexi Morin’s journey into the adult industry began with a Craigslist ad and a leap of faith. In 2011, fresh-faced and ambitious, she was scrolling through job ads on Craigslist when she stumbled upon a listing for an assistant makeup artist.

Women In Adult ·
profile

Still Rocking: The Hun Celebrates 30 Years in the Game

In the ever-changing landscape of adult entertainment, The Hun’s Yellow Pages stands out for its endurance. As one of the internet’s original fixtures, literally nearly as old as the web itself, The Hun has functioned as a living archive for online adult content, quietly maintaining its relevance with an interface that feels more nostalgic than flashy.

Jackie Backman ·
opinion

Digital Desires: AI's Emerging Role in Adult Entertainment

The adult industry has always been ahead of the curve when it comes to embracing new technology. From the early days of dial-up internet and grainy video clips to today’s polished social media platforms and streaming services, our industry has never been afraid to innovate. But now, artificial intelligence (AI) is shaking things up in ways that are exciting but also daunting.

Steve Lightspeed ·
opinion

More Than Money: Why Donating Time Matters for Nonprofits

The adult industry faces constant legal battles, societal stigma and workplace challenges. Fortunately, a number of nonprofit organizations work tirelessly to protect the rights and well-being of adult performers, producers and industry workers. When folks in the industry think about supporting these groups, donating money is naturally the first solution that comes to mind.

Corey D. Silverstein ·
opinion

Consent Guardrails: How to Protect Your Content Platform

The adult industry takes a strong and definite stance against the creation or publication of nonconsensual materials. Adult industry creators, producers, processors, banks and hosts all share a vested interest in ensuring that the recording and publication of sexually explicit content is supported by informed consent.

Lawrence G. Walters ·
opinion

Payment Systems: Facilitator vs. Gateway Explained

Understanding and selecting the right payment platform can be confusing for anyone. Recently, Segpay launched its payment gateway. Since then, we’ve received numerous questions about the difference between a payment facilitator and a payment gateway. Most merchants want to know which type of platform best meets their business needs.

Cathy Beardsley ·
Show More