Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Banner rotation javascript not working in Safari

Posted on 2008-06-18
2
Medium Priority
?
546 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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 nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.

916 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