Solved

Banner rotation javascript not working in Safari

Posted on 2008-06-18
2
535 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)
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.

739 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