Wrap your code in the [code] tags.
You shouldn't put the number for the array (3) because what if the user had more than 3 sets of ads?
You need to put type="text/javascript" in your script tag.
What if the user doesn't use images for ad's?
So, here's the code:
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Ad Set Code</title>
<!-- No Script Style Code -->
<style type="text/css">
.ad {
display:none;
}
</style>
</head>
<body>
<!-- This is the area for ads with computers that don't support/disabled scripting ability -->
<noscript>
<div id="noScriptAds">Add your no-script ad code here</div>
</noscript>
<!-- End Area -->
<div id="adSet1" class="ad">Ad Set 1</div>
<div id="adSet2" class="ad">Ad Set 2</div>
<div id="adSet3" class="ad">Ad Set 3</div>
<script type="text/javascript">
var adSets = 3 //How many ad sets are there
function randomAd() {
hideAds(adSets+1)
var i = Math.floor(Math.random() * adSets) + 1
var adCookie = getCookie('ad')
if (adCookie == i) {
setTimeout("randomAd()",1)
}
document.getElementById("adSet"+i).style.display = "block"
setCookie('ad',i,1)
}
function hideAds(no) {
for (i=1;i < no;i++) {
document.getElementById("adSet"+i).style.display = "none"
}
}
function getCookie( name ) {
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
function setCookie( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
if ( expires ) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name+"="+escape( value ) +
( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
window.onload = randomAd;
</script>
</body>
</html>
Added: Cookie saving so ads are different every page load
Bookmarks