• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 597
  • Last Modified:

JavaScript error starts appearing from website in Internet Explorer

I have a web page which includes a javascript that performs an image rotator which had been working fine even in Internet Explorer when I got it all setup just a few months ago, but now when I open this page, it indicates the following error details:

Line 42
Char: 3
Error: 'null' is null or not an object
Code: 0

when I go to my source code, it seems to be pointing to the following line of code:

  banner1.src=imgs1[currentAd1];

What I don't understand is why would it work before, and now it does not even with no changes, in Internet Explorer.  Intriguingly it does work when I open it in Firefox.
<script type="text/javascript">
 
var imgs1 = new Array("images/picture1.jpg",
"images/picture2.jpg",
"images/picture3.jpg",
"images/picture4.jpg");
 
var imgs2 = new Array("images/picture5.jpg",
"images/picture6.jpg",
"images/picture7.jpg",
"images/picture8.jpg");
 
var lnks1 = new Array("","","","");
var lnks2 = new Array("","","","");
var alt1 = new Array("","","","");
var alt2 = new Array("","","","");
var currentAd1 = 0;
var currentAd2 = 0;
var whichImg = 0;
var whichCtl = 2;
var imgCt1 = 4;
function cycle1() {
  if (currentAd1 == imgCt1) {
    currentAd1 = 0;
  }
  if (currentAd2 == imgCt1) {
    currentAd2 = 0;
  }
  if (whichImg == whichCtl) {
    whichImg = 0;
  }
var banner1 = document.getElementById('adBanner1');
var banner2 = document.getElementById('adBanner2');
var link1 = document.getElementById('adLink1');
var link2 = document.getElementById('adLink2');
  banner1.src=imgs1[currentAd1];
  banner2.src=imgs2[currentAd2];
  banner1.alt=alt1[currentAd1];
  banner2.alt=alt2[currentAd2];
  document.getElementById('adLink1').href=lnks1[currentAd1];
  document.getElementById('adLink2').href=lnks2[currentAd2];
  if (whichImg == 0) {
     currentAd1++; 
  }
  if (whichImg == 1) {
	 currentAd2++;
  }
  whichImg++;
}
  window.setInterval("cycle1()",2000);

Open in new window

0
accucom
Asked:
accucom
  • 2
  • 2
1 Solution
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
Can you provide some example page for that ? I paste this code to IE and it works ok :)
0
 
accucomAuthor Commented:
Here's the link in particular:

http://www.accucomci.com/index.php
0
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
I tried to install Microsoft Script Editor on this computer but I spent alot of time and I think that I found a problem without it :)

just try instead of:

  window.setInterval("cycle1()",2000);
 
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


do:


 
function MM_preloadImages() { //v3.0
  window.setInterval("cycle1()",2000);
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}




So this make sure that you refer to ID in document that is in fact created (2 sec can be not enough )
0
 
accucomAuthor Commented:
Thanks wilq32, that worked, and still worked on Firefox so I'm happy now.
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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