473,395 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Needs a urgent help with a rotating banner javascript code.

Hi,
I am not a good developer of Javascript codes. Needs this help to make
some modification to this famous free javascript from Anarchos. i am
using this in one of my webpage. What it does is, rotates banners with
hyperlink specific to each image. it works just perfect but i need a
simple modification. now I want to stop rotating the images when I
mouseover on the image, and then continue once I move the cursor out of
the banner image. Any one can help me please? Thanks in adv.

Rgds
RajSB
-----------the following code resides in a separate .js
file------------------

/****
* Banner Ad Rotater v3.02
* Anarchos > an*******@hotmail.com
* http://anarchos.xs.mw/bannerad.phtml
**/

function Banner(refreshTime, width, height, altText, start, random){
this.objName = "bannerAd" + (Banner.count++);
eval(this.objName + "=this");
if (!refreshTime) this.refreshTime = 5000; else this.refreshTime =
refreshTime*1000;
if (!width) this.width = 460; else this.width = width;
if (!height) this.height = 68; else this.height = height;
if (random == null) this.random = 1; else this.random = random;
this.altText = altText;
this.ads = [];
if (start) this.currentAd = start-1; else start = null;
this.mySize = 0;

this.Ad = function(src, href, target, mouseover) {
var tempImage = new Image();
tempImage.src = src;
this.ads[this.mySize] = new Object();
var ad = this.ads[this.mySize];
ad.src = src;
if (typeof(target) == "undefined" || target == null) ad.target =
"_self"; else ad.target = target;
ad.href = href;
ad.mouseover = mouseover;
this.mySize++;
}

this.link = function(){
var ad = this.ads[this.currentAd];
if (ad.target == "_self"){
location.href = ad.href;
}
else if (ad.target == "_blank" || ad.target == "_new"){
open(ad.href,this.objName + "Win");
}
else top.frames[ad.target].location.href = ad.href;
}

this.showStatus = function(){
var ad = this.ads[this.currentAd];
if (ad.mouseover) status = ad.mouseover;
else status = ad.href;
}

this.randomAd = function(){
var n;
do { n = Math.floor(Math.random() * (this.mySize)); }
while(n == this.currentAd);
this.currentAd = n;
}

this.output = function(){
var tempCode = "";
if (this.mySize > 1){
if (this.currentAd == null) this.randomAd();
if (this.currentAd >= this.mySize) this.currentAd = this.mySize - 1;
tempCode = '<a href="javascript:'+this.objName+'.link();"';
tempCode += ' onMouseOver="' + this.objName + '.showStatus(); return
true"';
tempCode += ' onMouseOut="status=\'\';return true">';
tempCode += '<img src="' + this.ads[this.currentAd].src + '"
width="' + this.width;
tempCode += '" name="' + this.objName + 'Img" height="' +
this.height + '" ';
if (this.altText) tempCode += 'alt="'+this.altText + '" ';
tempCode += 'border="0" /></a>';
document.write(tempCode);
this.nextAd();
} else document.write("Error: two banners must be defined for the
script to work.");
}

this.newAd = function(){
if (!this.random){
this.currentAd++;
if (this.currentAd >= this.mySize)
this.currentAd = 0;
}
else {
this.randomAd();
}
this.nextAd();
}

this.nextAd = function(){
document.images[this.objName+ 'Img'].src =
this.ads[this.currentAd].src;
setTimeout(this.objName+'.newAd()',this.refreshTim e)
}
}
Banner.count = 0;
----the following code to be embedded in a html page-----------

<script type="text/javascript">
// Author: Anarchos > an*******@hotmail.com >
http://anarchos.xs.mw/bannerad.phtml
<!--
myAd = new Banner( 5, 600, 100, "", 1, 0 );
myAd.Ad( "images/1.gif", "http://www.google.com", null, "Google" );
myAd.Ad( "images/2.gif", "http://www.yahoo.com", "_blank", "Yahoo.Com"
);
myAd.Ad( "images/3.gif", "http://www.msn.com", "_blank", "MSN.com" );
myAd.output();
// -->
</script>

May 10 '06 #1
2 2794
"sgMuser" <ra****@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Hi,
I am not a good developer of Javascript codes. Needs this help to make
some modification to this famous free javascript from Anarchos. i am
using this in one of my webpage. What it does is, rotates banners with
hyperlink specific to each image. it works just perfect but i need a
simple modification. now I want to stop rotating the images when I
mouseover on the image, and then continue once I move the cursor out of
the banner image. Any one can help me please? Thanks in adv.


Here's a solution:

1) Declare this variable:
var running = true;

2) Insert this line:
this.stopStart();
in this function:
this.showStatus = function() {

3) Add this function:
this.stopStart = function() {
(running) ? running = false : running = true;
if (running) this.nextAd();
else status = "";
}

4) Change this line
tempCode += ' onMouseOut="status=\'\';return true">';
to this:
tempCode += ' onMouseOut="' + this.objName + '.stopStart();
return true">';

5) Enclose the logic in
this.newAd = function() {
with:
if (running) {
}
May 10 '06 #2
McKirahan
Out of words to thank you! God Bless You! It works!

Rgds
RajSB

May 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: GujuBoy | last post by:
Hello All, I am farely new at PHP....I am looking for a ReDirection script with maybe the following features I need to have a "top" banner on my site with circulating banner ads so that it...
2
by: Derek | last post by:
I have some third party sponsor banners on my website and since installing the entire page pauses loading then displays the whole page. It seems that the page is waiting on the banners. Is there a...
2
by: mikeoley | last post by:
Ok what I'm trying to do should be fairly simple. I have an image on a page that rotates with 4 other images. All I want to do is be able to link this images to different parts of the site...
3
by: sunbeam | last post by:
Short Description of the Project: we developed a e-learning system for our students. each student has a unique username/password to view the modules he/she should view and nothing more. since we...
2
by: kwenterprise | last post by:
Hello All, I am normally great at figuring out ways around iframe issues that frustrate us all. I am using javasript to try and break an iframe that I have a banner rotator embedded in but it...
3
by: avalence | last post by:
Hello, I am trying to create a nice rotating earth globe (on mouse) on my web site, in order to display my professional relationships all over the world. The best way seems to be a javascript. In...
2
by: gwong123 | last post by:
Hi all. Not sure if this is the right place to ask this but I'm not sure which language would be best to find a good solution. Let me give you a quick overview before getting to the problem. ...
1
by: AR123 | last post by:
Hi I want to set up a rotating banner. Not sure how to incorporate my rotating banner code into the code below. I want the rotating banner to be the main feature image? This is set up in...
6
by: swethak | last post by:
Hi, I displayed the image taken from database.How to raotate that image using javascript.plz tell that how to start the logic.plz tell that some reference websites.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.