Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

joecool85

macrumors 65816
Original poster
Mar 9, 2005
1,355
4
Maine
Ok...here is what I need, a code that will let me have 3 images rotate with 3 corresponding links...they need to open OVER the frameset...in html you use target="_top" in the link code...but I can't get it to work in java. Here is what I have:

<HTML><HEAD>
<TITLE>Rotating banners with links</TITLE>

<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -

if (document.images) {
ads = new Array(3);
ads[0] = "images/tricon.jpg";
ads[1] = "images/ride250.jpg";
ads[2] = "images/jeepicon.jpg";
}

newplace = new Array(3);
newplace[0] = "http://www.thatraymond.com"
newplace[1] = "http://ride250.thatraymond.com"
newplace[2] = "http://jeep.thatraymond.com"

var timer = null
var counter = 0

function banner() {
timer=setTimeout("banner()", 4000);
counter++;
if (counter >= 3)
counter = 0;
document.bannerad.src = ads[counter];
}

function gothere() {
counter2 = counter;
window.location.href = newplace[counter2];
}


// - End of JavaScript - -->
</SCRIPT>

</HEAD>
<BODY BGCOLOR="#000000" onload="banner()">

<a href="javascript:gothere()"><IMG SRC="images/tricon.jpg" WIDTH="65" HEIGHT="57" BORDER="0" NAME="bannerad"></a>

</BODY>
</HTML>

Thanks!
 
I thought I could help, but that's not Java. It's JavaScript. Unfortunate that the names are similar, but there's no connection between the two.
 
Sorry...hopefully someone on here will know though :) I'm not too worried, we have a bunch of smart people on here.
 
If this page is part of a frameset and you wish to replace the frameset with a new page, you will have to change

Code:
window.location.href = newplace[counter2]

to

Code:
parent.location.href = newplace[counter2]
 
Awesome, you are the man! I actually had to change it to top not parent...my page loads with a frame that is left and right, then another frameset within...so it was loading on the left lol. But I got it now thanks to you! I love macrumors!!
 
joecool85 said:
Awesome, you are the man! I actually had to change it to top not parent...my page loads with a frame that is left and right, then another frameset within...so it was loading on the left lol. But I got it now thanks to you! I love macrumors!!

Glad you got it. Alternatively you could have used parent.parent ;)
 
That's good to know. I'm glad I'm finally learning some javascript. I'm a new media major at the University of Maine and as far as coding goes all I know is HTML lol. Thanks again!
 
If that code for ad like banners does not work here is a good code that helped me out many times

PHP:
			<script  type="text/javascript"> 
			   var how_many_ads = 3;
			   var now = new Date()
			   var sec = now.getSeconds()
			   var ad = sec % how_many_ads;
			   ad +=1;
			   if (ad==1) {
			   txt="Name Here";
			   url="http://xxxxxxxx.net";
			   alt="Name Here";
			   banner="http://xxxxxxxxxx.com/xxxxx.jpg";
			   width="125";
			   height="125";
			   }
			   if (ad==2) {
			   txt="Name Here";
			   url="http://xxxxxxxx.com/";
			   alt="Name Here";
			   banner="http://xxxxxxxx.com/xxxx.jpg";
			   width="125";
			   height="125";
			   }
			   if (ad==3) {
			   txt="Name Here";
			   url="http://xxxxxxxx.com/";
			   alt="Name Here";
			   banner="http://xxxxxxxx.com/xxxx.jpg";
			   width="125";
			   height="125";
			   }
			   document.write('<center>');
			  document.write('<a href=\"' + url + '\" target=\"_top\">');
			  document.write('<img src=\"' + banner + '\" width=')
			  document.write(width + ' height=' + height + ' ');
			  document.write('alt=\"' + alt + '\" border=0><br>');
			  document.write('<small>' + txt + '</small></a>');
			  document.write('</center>');
			  // End --></SCRIPT>
 
No problems with the JavaScript so far...I haven't even so much as dabbled in php yet, I probably should though. Maybe on my next project.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.