PDA

View Full Version : Need Help With Javascript Banner Rotator!


Strategy
05-31-2002, 05:38 PM
If any of you could help, it would be greatly appreciated!

I am trying to get the links I have put into the script to open in a new window. Now, according to the instructions, I CAN do this - IF my site is in frames. However, it is not, and I am lost! The script I am trying to use is below.

I have tried changing the location.href=durl[sctr]; line to read new.location, parent.location...I have even tried to do a target="top" or "new" or "blank" in the urls, and I get an error on the page every time, and a bad gateway error when I click on the x'd out image!

You can view the code in action at: http://strategyadservice.com/index2.htm
(banners are at the bottom of the white table)

Please note that the code on the above page loads properly only because the links open in the current window, which is not what I want them to do *grr*

Thanks again everyone!!!

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

<!-- Hide from JavaScript-Impaired Browsers
/* First, if you load fewer or more than 6 sponsors
into your rotator, change the "number_of_sponsors" variable
to the actual number of sponsor .gifs you plan to
load. */
number_of_sponsors=6;

var sctr=0;
var halt=0;
var isn=new Array();
for (i=0;i<number_of_sponsors;i++){
isn[i]=new Image();
}

/* The sponsor .gif names are loaded into the isn[x]
sponsor images array. You may load any number of
sponsor images (.gif or .jpg or both) into this
array. They must all be the same size, however.
Substitute your own .gif filenames for the ones
shown here. Note that the first .gif must appear
in the isn[0] array element. */
isn[0].src="http://www.yourplace/netad.gif";
isn[1].src="http://www.yourplace.gif";
isn[2].src="http://www.yourplace.gif";
isn[3].src="http://www.yourplace.gif";
isn[4].src="http://www.yourplace.gif";
isn[5].src="http://www.yourplace.gif";

/* Finally, replace the URL's below with those of
your sponsors IN THE SAME ORDER. */
var durl=new Array();
durl[0]="http://www.adobe.com/aic/";
durl[1]="http://www.pacificcoast.com/entry.infohiway";
durl[2]="http://www.infohiway.com/webwalker";
durl[3]="http://info.netscape.com/sban11_e";
durl[4]="http://www.infohiway.com/javascript/hts.htm";
durl[5]="http://www.pentax.com/";

/* This script is set to rotate every 10 seconds.
(5000=5 seconds, so 30000 would equal 30, etc)
You should change the number in the setTimeout()
call below for the number of seconds you wish. */
function rotateIt(){
if (halt!=1){
sctr++;
if (sctr>number_of_sponsors-1){
sctr=0;
}
document.sponsor.src=isn[sctr].src;
setTimeout("rotateIt()",10000);
}
}

/* This code will work just fine with or without
frames. However, if you are in frames and wish
to replicate the TARGET="_top" call to remove
frames, change the location.href call to:
parent.location.href=durl[sctr];
below. */
function doIt(){
halt=1;
location.href=durl[sctr];
}

function dispIt(){
parent.window.status=durl[sctr];
}
// End Hiding -->

</SCRIPT>

<center><table BORDER=0 CELLSPACING=0 CELLPADDING=0 >
<tr>
<td><a href="http://your url.html" onClick="doIt();return false" onMouseover="dispIt();return true;"><img SRC="http://whatever the name is.gif" NAME="sponsor" BORDER=0 height=60 width=468></a></td>
</tr>
</table></center>
<!-- this script and more free from a1javascripts.com -->


===========================================
===========================================
PLEASE NOTE: this last part must be placed at the bottom of the page.

<!-- -->
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide JavaScript from Java-Impaired Browsers
sctr=0;
rotateIt();
// End Hiding -->
</SCRIPT>
<!-- -->:mad: :mad:

cpradio
06-02-2002, 08:26 AM
Can you provide a link to the site you are attempting to use this on?

And do any error messages appear?

-Matt

Strategy
06-02-2002, 09:43 AM
Hi Matt,

You can see the code in action at:
http://strategyadservice.com/index2.htm

Now, I do have a programmer friend who says it's impossible to get the links to open in new windows with this script....just so you don't waste hours of your time like he did.

Thanks :)

cpradio
06-02-2002, 11:07 AM
Try this:

change: location.href=durl[sctr];
to: window.open(durl[sctr]);

-Matt

Strategy
06-03-2002, 09:25 AM
OMG.....
It WORKED! The links open in new windows! Thank you thank you thank you!

But....*lol*

You'll never guess what's happening now!! I can click on a link and it opens in a new window, but then the banner rotation on my page stops. I have to refresh the page to get it going again.

Very strange....

Strategy
06-03-2002, 09:26 AM
Forgot to mention that the script is now at:

http://www.strategyadservice.com in stead of /index.2

cpradio
06-03-2002, 05:30 PM
To fix the halting problem remove the following line from the doit() function

halt=1;

-Matt

Strategy
06-03-2002, 05:58 PM
Fantastic, Matt!

It worked :)

Thanks so much for all of your help - it's nice to be able to put this beast to rest!
:D

cpradio
06-03-2002, 05:59 PM
I know exactly what you mean :D

smudgex
04-13-2003, 11:32 PM
what about if you wanted that new window to contain the menu bar etc.