Solved

Banner rotation javascript not working in Safari

Posted on 2008-06-18
2
530 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
Comment Utility
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
Comment Utility
Amazing!! Thanks!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I had to do a bit of research to find the answer to this question so I thought I'd share my results.  Due to our outdated mainframe systems, we need to downgrade IE9 to IE8 in order to stay compatible.  We also needed to downgrade Java.  In order to…
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

762 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

11 Experts available now in Live!

Get 1:1 Help Now