Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Mac&PC compatible JavaScript

Check out this page:
http://gamtu.netscope.co.za/experiments/default.stm

It does exactly what I want on a PC&IE5, but it needs to work under Mac too.

Anyone?
0
ayrezyle
Asked:
ayrezyle
  • 8
  • 7
  • 2
1 Solution
 
ayrezyleAuthor Commented:
Here is the code I currently use; I need it to work on a Mac too:

<html>

<body onload="javascript:Init()">

<script language="javascript">
// <!--

// note the BODY tag above; the onload event is used to set up the list of image filenames

      var numberOfImages = 5;            // how many images do you have?
      var numberOfSeconds = 2;      // how long between image swaps?
      var rndnum = Math.random();

      var counter = Math.round(numberOfImages * rndnum + 1);
      var imgList = new Array(numberOfImages);      // to store the filenames

// -->
</script>

      
<script language="javascript">
// <!--

function Init() // set up the list of filenames
{
      imgList[1] = "images/form-over.jpg"; // remember to change the first actual image to match this one!
      imgList[2] = "images/gallery-over.jpg";
      imgList[3] = "images/home-over.jpg";
      imgList[4] = "images/pricing-over.jpg";
      imgList[5] = "images/gallery-over.jpg";
      setInterval(nextBanner,numberOfSeconds*1000); // this sets how often "nextBanner" will be called
}

// -->
</script>


<script language="javascript">
// <!--

function nextBanner() // activates the next image in the list (will roll over to the first)
{
      if (counter >= numberOfImages)
      {
            counter = 1;
            document.images.item("banner").src = imgList[counter];
      } else {
            counter++;      
            document.images.item("banner").src = imgList[counter];
      }
}

// -->
</script>

<center><img id="banner" SRC="images/gallery-over.jpg" width="109" height="32"></center>

This page currently swaps images at a 2 second interval.

</body>
</html>
0
 
mgfranzCommented:
What version of browser on the Mac?  I see nothing wrong with the scripts...
0
 
ayrezyleAuthor Commented:
Apparently IE4.5 Does that exist for the Mac? I don't even know, I was never bothered with Mac before. I know the above code runs fine on my PC with Win2k and IE5, but I have no way to test it on a Mac. Any ideas?
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
mgfranzCommented:
Looks like an issue with the scripts, cause they don't work with IE4.7.

Let me do some work on it.
0
 
davlun20080Commented:
Try using this, putting the scripts in your <head>...</head>

<script language="javascript">
<!--
var numberOfImages = 5; // how many images do you have?
var numberOfSeconds = 2; // how long between image swaps?
var rndnum = Math.random();
var counter = Math.round(numberOfImages * rndnum + 1);
var imgList = new Array(numberOfImages); // to store the filenames

function nextBanner(){
      if (navigator.appName != "Netscape"){
            if (counter >= numberOfImages){
                  counter = 1
                  document.images.item("banner").src = imgList[counter]
            } else {
                  counter++
                  document.images.item("banner").src = imgList[counter]
            }
      } else {
            if (counter >= numberOfImages){
                  counter = 1;
                  document.images['banner'].src = imgList[counter]
            } else {
                  counter++
                  document.images['banner'].src = imgList[counter]
            }
      }
}

function Init(){
      imgList[1] = "images/testimage1.gif";
      imgList[2] = "images/testimage2.gif";
      imgList[3] = "images/testimage3.gif";
      imgList[4] = "images/testimage4.gif";
      imgList[5] = "images/testimage5.gif";
      setInterval("nextBanner()",numberOfSeconds*1000);
}

// -->
</script>


<body onload="JavaScript:Init()">

The setInterval was not called correctly and it needs to call the function, after the function has been declared.  I also added functionality for NS if needed.

davlun
0
 
davlun20080Commented:
Forgot to mention, I renamed the image in the body of your doc to name="" rather than id="".  This was to accomodate NS.

davlun
0
 
ayrezyleAuthor Commented:
OK I made the changes you suggested, but apparently it's still not working. IE5 for the PC handles it just fine though.

Here's the URL again for anyone with a Mac:
http://gamtu.netscope.co.za/experiments/default.stm
0
 
davlun20080Commented:
Are you getting a particular error message?  Is it a script error or is the page just not functioning?

davlun
0
 
ayrezyleAuthor Commented:
It apparently just doesn't do anything.
0
 
davlun20080Commented:
Well I am not sure then either since I do not have a mac, but I do know it now works in IE4+, you said it works in IE5, works in NS4.7 so I think it is working in most of what is out there.  The only thing I can think of is something I rememeber reading a long time ago about mac's not liking the random function.

I will remove and repost code:
davlun
0
 
davlun20080Commented:
Try this without the random number.  If it works, you can get a script that will give you a near random number without using the Math.random(), I thought I had one but could not find it.

<html>
<HEAD>
<TITLE>SOME TITLE</TITLE>
 
<script language="javascript">
<!--
var numberOfImages = 5; // how many images do you have?
var numberOfSeconds = 2; // how long between image swaps?
var thisdate = new Date()
var thisdate2 = new Date()
counter= Math.round((thisdate.getTime()/thisdate2.getDate())*.0000000001)
var imgList = new Array(numberOfImages); // to store the filenames

function nextBanner(){
      if (navigator.appName != "Netscape"){
            if (counter >= numberOfImages){
                  counter = 1
                  document.images.item("banner").src = imgList[counter]
            } else {
                  counter++
                  document.images.item("banner").src = imgList[counter]
            }
      } else {
            if (counter >= numberOfImages){
                  counter = 1;
                  document.images['banner'].src = imgList[counter]
            } else {
                  counter++
                  document.images['banner'].src = imgList[counter]
            }
      }
}

function Init(){
      imgList[1] = "images/testimage1.gif";
      imgList[2] = "images/testimage2.gif";
      imgList[3] = "images/testimage3.gif";
      imgList[4] = "images/testimage4.gif";
      imgList[5] = "images/testimage5.gif";
      setInterval("nextBanner()",numberOfSeconds*1000);
}

// -->
</script>

</head>

<body bgcolor="#006666" onload="JavaScript:Init()">
<center>
  <img name="banner" SRC="images/testimage1.gif" width="250" height="175">
</center>
</body>
</html>


davlun
0
 
ayrezyleAuthor Commented:
Interesting way of getting a randomish number! I'll hard code the number as well to see if that helps. Time for some more testing...
0
 
davlun20080Commented:
As for the random part, since you are working with a narrow number of images, many will default to the >= category.  Depending on the day of the month, the numbers can fall between 1 and 12 from my testing but I have never used it where precision counted so I did not test a lot.

davlun
0
 
ayrezyleAuthor Commented:
That's fine, I was just teasing. I asked a friend with a Mac to check out that code. I'll assign the points as soon as we know if it works.
0
 
davlun20080Commented:
Everything working?
0
 
ayrezyleAuthor Commented:
No that still wasn't it, but since we're not getting anywhere, nevermind. I'll go to the client and try it from the Mac itself. Then at least I can take it step by step and I won't be working in the dark.

Thanks for the input, you can have the points even though we didn't get to a solution.
0
 
ayrezyleAuthor Commented:
SOLUTION! Check out our final solution. It was simply the MAC that was full of BS.

The site is now up & running at www.helderbergcompass.co.za

Thanks for the support!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 8
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now