Solved

Banner rotation javascript not working in Safari

Posted on 2008-06-18
2
531 Views
Last Modified: 2013-12-07
Dear all,

I have the code below, that rotates banners every 3 seconds. It works great in all browsers but Safari.
Can anyone please tell me that do I have to change for it to work in Safari??

Thanks a lot in advance!
<html>

<HEAD>
 

<script language="JavaScript" type="text/JavaScript"><!--
 

var urlArray = new Array(4);

var banArray = new Array(4);

var counter = 1;

var url = "http://www.google.com"; //  initial URL
 

//añade URL

urlArray[0] = "http://www.yahoo.com";

urlArray[1] = "http://www.yahoo.fr";

urlArray[2] = "http://www.yahoo.de";

urlArray[3] = "http://www.yahoo.it";
 

if(document.images) //pre-load imagenes

{

  for(i = 0; i < 3; i++)

  {

    banArray[i] = new Image(312, 38);

    banArray[i].src = "banners/banner" + (i+1) + ".png";

  }

}
 
 

function changeBanner()

{

  if(counter > 2)

   counter = 0;
 

  document.banner.src = banArray[counter].src;
 

  url = urlArray[counter];

  counter++;

}
 

//changes time (min * 60000) o (sec * 1000)

var timer = window.setInterval("changeBanner()", 3000);
 

//--></script>

</HEAD>
 

  <body>

<a href="#" onClick="window.open(url,'BannerWin');">

<img src="banners/banner5.png" width=312 height=38 border=0 name="banner"></a>
 

  </body>

</html>

Open in new window

0
Comment
Question by:Dada44
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21811695
Try:
<script language="JavaScript" type="text/JavaScript"><!--
var timer=null;
var urlArray = new Array();
var banArray = new Array();
var counter = 1;
var url = "http://www.google.com"; //  initial URL
 
//a?ade URL
urlArray[0] = "http://www.yahoo.com";
urlArray[1] = "http://www.yahoo.fr";
urlArray[2] = "http://www.yahoo.de";
urlArray[3] = "http://www.yahoo.it";
 
if(document.images) //pre-load imagenes
{
  for(i = 0; i < 3; i++)
  {
    banArray[i] = new Image(312, 38);
    banArray[i].src = "banners/banner" + (i+1) + ".png";
  }
}
 
 
function changeBanner()
{
  if(counter > 2)
   counter = 0;
 
  document.banner.src = banArray[counter].src;
 
  url = urlArray[counter];
  counter++;
  timer = setTimeout("changeBanner()", 3000);
}
 
//changes time (min * 60000) o (sec * 1000)
timer = setTimeout("changeBanner()", 3000);
 
//--></script>
</HEAD>
 
  <body>
<a href="#" onClick="window.open(url,'BannerWin');">
<img src="banners/banner5.png" width=312 height=38 border=0 name="banner"></a>
 
  </body>
</html>

Open in new window

0
 

Author Closing Comment

by:Dada44
ID: 31468286
Amazing!! Thanks!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now