Solved

Mac&PC compatible JavaScript

Posted on 2000-03-15
17
190 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
[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
  • 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Industry Leaders: 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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

690 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