PDA

View Full Version : Java gurus, I need help!




joecool85
May 9, 2005, 12:02 PM
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!



plinden
May 9, 2005, 12:05 PM
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.

joecool85
May 9, 2005, 12:08 PM
Sorry...hopefully someone on here will know though :-) I'm not too worried, we have a bunch of smart people on here.

jeremy.king
May 10, 2005, 05:36 PM
If this page is part of a frameset and you wish to replace the frameset with a new page, you will have to change

window.location.href = newplace[counter2]

to

parent.location.href = newplace[counter2]

joecool85
May 11, 2005, 10:11 AM
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!!

jeremy.king
May 11, 2005, 11:41 AM
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 ;)

joecool85
May 11, 2005, 12:03 PM
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!

MacEffects
May 11, 2005, 12:03 PM
If that code for ad like banners does not work here is a good code that helped me out many times



<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>

joecool85
May 11, 2005, 01:12 PM
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.