Solved

Mac&PC compatible JavaScript

Posted on 2000-03-15
17
187 Views
Last Modified: 2013-12-25
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
Comment
Question by:ayrezyle
  • 8
  • 7
  • 2
17 Comments
 
LVL 1

Author Comment

by:ayrezyle
ID: 2620264
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
 
LVL 18

Expert Comment

by:mgfranz
ID: 2620433
What version of browser on the Mac?  I see nothing wrong with the scripts...
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 2620787
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 18

Expert Comment

by:mgfranz
ID: 2620944
Looks like an issue with the scripts, cause they don't work with IE4.7.

Let me do some work on it.
0
 
LVL 3

Expert Comment

by:davlun20080
ID: 2631971
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
 
LVL 3

Expert Comment

by:davlun20080
ID: 2632081
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
 
LVL 1

Author Comment

by:ayrezyle
ID: 2634940
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
 
LVL 3

Expert Comment

by:davlun20080
ID: 2634944
Are you getting a particular error message?  Is it a script error or is the page just not functioning?

davlun
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 2635511
It apparently just doesn't do anything.
0
 
LVL 3

Expert Comment

by:davlun20080
ID: 2638582
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
 
LVL 3

Expert Comment

by:davlun20080
ID: 2638676
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
 
LVL 1

Author Comment

by:ayrezyle
ID: 2639726
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
 
LVL 3

Expert Comment

by:davlun20080
ID: 2640953
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
 
LVL 1

Author Comment

by:ayrezyle
ID: 2644062
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
 
LVL 3

Accepted Solution

by:
davlun20080 earned 50 total points
ID: 2659231
Everything working?
0
 
LVL 1

Author Comment

by:ayrezyle
ID: 2660473
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
 
LVL 1

Author Comment

by:ayrezyle
ID: 2668838
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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to count occurrences of each item in an array.

785 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