Random Ads
General
Do you want to display your own ads on your Web site? If you have a large number of them and only want to display a few at a time, this script will do it. They will display in random order, either horizontally or vertically.
The ads displayed below each have a link to the Web site of the advertiser and will change when the page is refreshed.
Notes
- Created by: Michael Stransky
- Web Site: http://www.stransky-webdesigns.com/
- Posted: January 24, 2007
1. To show the ads vertically, change the script on the page to
<script type="text/javascript">
randomorder(adblock, '<br><br>')
</script>
2. To show the ads horizontally change the script on the page to
<script type="text/javascript">
randomorder(adblock, ' ')
</script>
3. The following portion of the code determines how many ads to display
var randomorder=new Array()
var the_one
var z=9
for (i=0;i<targetarray.length;i++)
randomorder[i]="i"
The value of the "z" variable is very important. If you have 20 ads but only want to display 4 ads at a time, you would change the value of the "z" variable to "z=16" (without the quotes). This means that out of 20 ads, 16 will be hidden.
Source Code
Paste this source code into the designated areas.
External file
Paste this code into an external JavaScript file named: randomAds.js
CSS
Paste this code into your external CSS file or in the <style> section within the HEAD section of your HTML document.
Head
Paste this code into the HEAD section of your HTML document.
Body
Paste this code into the BODY section of your HTML document


Leave a Response
(7 comments)Thank you so much for this simple and elegant script - it was just what I was looking for - you rock!
This script works great. I've been to so many places to get something to work right and this works. I'm new to code writing only been doing for about 5 months and wrote my whole website so this is great! Thanks!
You need to submit your question to the [a href="http://www.webdeveloper.com/forum/forumdisplay.php?f=3"]JavaScript Forum[/a].
i don't know if it is possible to display 1 image at a time, would really like if it did and also be able to put it in different areas of my webpage. Would appreciate any help given.
It works in IE and FF. You will need to post your problem on the [a href="http://www.webdeveloper.com/forum/forumdisplay.php?f=3"]JavaScript Forums[/a] or the [a href="http://www.webdeveloper.com/forum/forumdisplay.php?f=40"]FrontPage forums[/a]