Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Banner rotation javascript not working in Safari

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
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…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

704 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