Turn your Mobile Apps into m-commerce apps – Learn More!
 

Code Snippets

  

JavaScript Source Code


You're Browsing As A Guest! Register Now...
Become an Expert!

Join 414,937 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,674 people online right now.Registration is fast and FREE... Join Now!




Random Banner Generator

Creates an image ad based on links and images stored in arrays.

Submitted By: kewlkreator
Actions:
Rating:
Views: 456

Language: JavaScript

Last Modified: August 28, 2009
Instructions: Just change the variables at the top (they're labeled). Place the script in the body or head of your HTML document.

Snippet


  1. <script>
  2. /*------------START VARIABLES------------*/
  3. var width = "468";
  4. //Your image's width
  5. var height = "60";
  6. //Your image's height
  7. var title = "Click Here";
  8. //Your image's title (when the mouse hovers)
  9. var alt = "A ad";
  10. //Your image's alternate text (if the image links are duds)
  11. var target = "_blank"
  12. //For opening a new window.
  13. var border = "1"
  14. //Border size in pixels
  15. /*------------END VARIBLES------------*/
  16. /*------------START IMAGES------------*/
  17. var ad=new Array()
  18. //The array of ads
  19. //Make sure they are images!
  20. ad[0]='www.ad.com/ad1.gif';
  21. ad[1]='www.ad.com/ad2.gif';
  22. ad[2]='www.ad.com/ad3.gif';
  23. ad[3]='www.ad.com/ad4.gif';
  24. /*------------END IMAGES------------*/
  25. /*------------START LINKS------------*/
  26. var links=new Array()
  27. //The array of links
  28. links[0]='http://www.link1.com';
  29. links[1]='http://www.link2.com';
  30. links[2]='http://www.link3.com';
  31. links[3]='http://www.link4.com';
  32. /*------------END LINKS------------*/
  33. var xy = Math.floor(Math.random()*ad.length);
  34. //Gets a random number for the links and url's
  35. document.write('<a href="'+links[xy]+'" target="+target+"><img src="'+ad[xy]+'" width="'+width+'" height="'+height+'" alt="'+alt+'" border="0" /></a>');
  36. //Write the link and image
  37. </script>

Copy & Paste


Comments

paperclipmuffin 2009-08-31 01:24:38

Great! Shows the principles on which banner ads work! Well done! :)

kewlkreator 2009-08-31 06:25:44

Thanks! :D


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.