Go Back   SZONE.US Forums > Do it yourself (DIY) > Web Tips

Web Tips Tips and tricks specializing in programming languages of the web. ie. PHP, MYSQL, XHTML, CSS, etc

javascript random banner code

Views:7717
Reply
Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average.
  #1  
Unread 02.18.07, 01:14 PM
Zachariah Boren's Avatar
Zachariah Boren Zachariah Boren is offline
Administrator
 
Join Date: 02.07
Location: Canoga Park, CA
Posts: 928
Blog Entries: 6
Images: 10075
Send a message via ICQ to Zachariah Boren Send a message via MSN to Zachariah Boren Send a message via twitter to Zachariah Boren
javascript random banner code

Hello,

I had the need to rotate a few image banners with links to their websites. Here is a simple Javascript that will pick at random a image and refreash per page load.

EX:
I want to show 3 images and link to 3 websites.

image1.jpg @ http://www.yoursite1.com
image2.jpg @ http://www.yoursite2.com
image3.jpg @ http://www.yoursite3.com


Code:
<script language="javascript" type="text/javascript">
<!-- 
function banner() { 
}; 

banner = new banner(); 
number = 0; 

// bannerArray 
banner[number++] = "<a href='http://www.yoursite1.com' target='_blank'><img src='/banners/image1.jpg' alt='' border='0' /></a>"
banner[number++] = "<a href='http://www.yoursite2.com' target='_blank'><img src='/banners/image2.jpg' alt='' border='0' /></a>"
banner[number++] = "<a href='http://www.yoursite3.com' target='_blank'><img src='/banners/image3.jpg' alt='' border='0' /></a>" 
 
// keep adding items above here... 

increment = Math.floor(Math.random() * number); 
document.write(banner[increment]); 

//-->
</script>
Useage: If you need more banners edit / add another row.
Code:
banner[number++] = "<a href='http://www.yoursite1.com' target='_blank'><img src='/banners/image1.jpg' alt='' border='0' /></a>"
Link of Destination
Image location
__________________
http://www.szone.us | http://www.gzhq.net
Twitter | Facebook | My:Hacks @ vBulletin.org
Member of Kiwanis Club of Chatsworth
Reply With Quote
  #2  
Unread 09.20.08, 12:39 AM
Logan
Guest
 
Posts: n/a
Thanks

Used this code on my site, just wanted to say thanks. Just what i needed; simple, clean, easy to use.
Reply With Quote
Reply

Tags
banner, code, javascript, random

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
[vB 3.6.x] Add a banner image to each forum Zachariah Boren vBulletin 3.6x / 3.8x 2 02.06.08 06:11 AM
The Star-Spangled Banner Zachariah Boren Freedom information 0 04.30.07 03:17 PM
The Star-Spangled Banner Zachariah Boren Writing 0 09.12.05 05:04 PM


All times are GMT -8. The time now is 08:18 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2007 - 20017 SZONE.US All rights reserved
You Rated this Thread: