Random Javascript Header
Submitted by delaigle on Tue, 04/03/2007 - 19:12
Ok so I really wanted a random changing banner on the site that would not hinder page load so I decided to use javascript so that loading would be dependent on the users computer not the server, not to mention I really did not want to do this via php because well, I thought it would be best not to use the server to figure out which banner to use. So just in case anyone would like to do the same here is the code I used to do it.
<script language="Javascript"> <!-- window.onload=function(){ //this is where you place the images you want to use var banners = ["bridge_header.gif", "mtl_savings_banner.jpg", "tile_banner.jpg"]; //be sure to change the front part of the url document.getElementById("header").style.backgroundImage = "url(/images/" + banners[Math.floor(Math.random()*banners.length)] +")"; } //--> </script>
Add new comment
recent comments
- That sucks
16 weeks 3 days ago - Awesome writeup.
16 weeks 3 days ago - its only a matter of time
29 weeks 3 days ago


