Rotating banner using JavaScript

Currently at work we are using an Adobe Flash® for an ad rotator to show different promotions to our customers. Due to recent issues we are trying to come up with a way to improve the process to make updating it, as easy as possible. Not being a flash guy, I decided to venture out to find a solution using JavaScript. After a quick Google® search nothing peaked my interest, so I decided to try and write the solution from scratch. While in the end, my solution didn't work out, I created what I believe to be a nice piece of code that I could share with the rest of you.

While pretty standard I'm sure, this script will work for anything from images, to swf files, to basic text. It is done utilizing the DOM and .innerHTML. So, here it is.

JavaScript

<script type="text/javascript">
function mySlideshow() {
	var elem= document.getElementById('idHere'); // DIV ID of HTML to replace
 
	if (elem){
		elem.innerHTML = 'codeHere' // place the code you want in the elem DIV here
	}
	setTimeout("slide2();",7000);	// wait in milliseconds before starting slideTwo function
}
function slide2() {
	var elem= document.getElementById('idHere'); // DIV ID of HTML to replace
 
	elem.innerHTML = 'codeHere'  // place the code you want in the elem DIV here
	setTimeout("slide3()",7000); 	// wait in milliseconds before starting slideTwo
}
function slide3() {
	var elem= document.getElementById('idHere'); // DIV ID of HTML to replace
 
	elem.innerHTML = 'codeHere'  // place the code you want in the elem DIV here
	setTimeout("mySlideshow();",8000); // wait in milliseconds before restarting
}
</script>

HTML Code

<!-- place the ONLOAD attribute in the BODY tag -->
<body onload="mySlideshow" ...>
 
<!-- place this div wherever you want the changes to take place -->
<div id="objPersonal">...place initial "elem" code here in case browser doesn't support JavaScript...</div>

If you have any questions or comments please let me know.

Keep on taggin'
:cD

Visitor's picture
Samantha commented on #11

Hi there, great post! I stumbled upon it by googling a solution for a small site I'm trying to get up. I know my questions are going to sound like absolute tech dumbness, but I really am a newbie in all this. Anyways, here goes: I would like to put up rotating quotes and a rotating banner, and I'm using a simple install of Drupal 6, but I cant see where to put the items I want to rotate in your code. I know it must be dead obvious for a coder, but I dont know where to start. Please help with an example?

Many kind regards

Visitor's picture
kaidy commented on #12

It simply contains a generic, white-colored upper with multiple black hints in the form of

the swoosh, midsole, laces among other places.http://www.just-nike.com/nike-air-

jordan-c-1.html">Nike Soccer Boot is now available at select retailers

overseas and available for pre-order at Eastbay.your hands are full of Nike Soccer Boot

.you will be so nice ..there are so many kind of fashion women's design r You

know why I love air

sneakers. If you enter one of http://www.cheap-

wholesaler.com">air sneakers on the floor, and look at if from the

side, you see that part of the sole under the toes and heels do not actually hit the floor.

We’ve already covered why you need to own a cheap handbags wholesaleand a

fashion celebrity accessory.

reply Email this comment

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><img>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <css>, <drupal>, <java>, <javascript>, <mysql>, <php>, <ruby>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA

This question is for testing whether you are a human visitor and to prevent automated spam submissions.