473,651 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script works in Firefox, not in IE

cjl
Hey all:

Just getting my feet wet with javascript. The following script works
fine in Firefox, but won't run in IE. In fact, I've included this
script as an external file in the <head> of my html file, and the
remainder of the page doesn't load at all in IE. If I remove the
<script>, the page loads in IE.

var images = new Array();
var firstImage = 2;
var lastImage = 27;
var timeout_state = null;
var counter = 0;
var running = 0;

for (counter=firstI mage;counter<=l astImage;counte r++)
{
images[counter] = new Image();
images[counter].src = counter + ".jpg";
}

counter = firstImage;

function switchImage()
{
if(running == 0)
{
running = 1;
animate();
}
else
{
running = 0;
clearTimeout(ti meout_state);
timeout_state = null;
}
}

function animate(element )
{
if (counter >= lastImage) {counter = firstImage;}
document.getEle mentById('right ').src = images[counter].src;
counter++;
timeout_state = setTimeout("ani mate()", 50);
}

Any help?

-CJL

Jul 23 '05 #1
3 1744
ASM
cjl wrote:
Hey all:

Just getting my feet wet with javascript. The following script works
fine in Firefox, but won't run in IE. In fact, I've included this
script as an external file in the <head> of my html file, and the
remainder of the page doesn't load at all in IE. If I remove the
<script>, the page loads in IE.
function animate(element )
{
if (counter >= lastImage) {counter = firstImage;}
document.getEle mentById('right ').src = images[counter].src;
try :
document.getEle mentById('right ').src = eval(images[counter]+'.src');

try also putting a var right=''; at top of JS
or prefer :
document.getEle mentById(elemen t).src = images[counter].src;
and
timeout_state = setTimeout("ani mate("+element+ ")", 50);

IE doesn't like uknonwn objects and in your JS
the page object 'right' is used but not yet seen
counter++;
timeout_state = setTimeout("ani mate()", 50);
}


and overall don't run animate() before complete loading of the page
-> preferable to put a JS for that just before </html>

and let some time to IE it catches your 26 images
--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #2
cjl
Hey all:

OK, the problem was with my html, not my javascript.

I had:
<script src="pre.js" >

When I needed
<script src="pre.js" ></script>

I wasn't providing the closing tag, which IE 6 didn't like, but Firefox
ignored.

-CJL

Jul 23 '05 #3
On 08/06/2005 14:40, ASM wrote:
cjl wrote:
Just getting my feet wet with javascript. The following script works
fine in Firefox, but won't run in IE.

I cannot see anything in what you've posted that will not work in IE
5.x+. Please post a URL to an example - it's much easier to diagnose.

Some alternative code is included at the end of this post (though it is
untested).

[snip]
try :
document.getEle mentById('right ').src = eval(images[counter]+'.src');
Randomly throwing eval about will *NEVER* solve a problem.
try also putting a var right=''; at top of JS
What do you think that will do?
or prefer :
document.getEle mentById(elemen t).src = images[counter].src;
and
timeout_state = setTimeout("ani mate("+element+ ")", 50);


That seems sensible, but it won't fix the OP's code.

[snip]

Mike
function Animation(name, images, rate) {
var current = 0,
element = document.images[name],
timer;

function animate() {
element.src = images[current];
current = (current + 1) % images.length;
timer = setTimeout(anim ate, rate);
}

if(!element || ('function' != typeof setTimeout)
|| ('function' != typeof clearTimeout))
{
return null;
}

animate.toStrin g = function() {
return 'Animation[' + name + ']();';
};
Animation[name] = animate;

this.preload = function() {
if('function' == typeof Image) {
for(var i = 0, n = images.length, t; i < n; ++i) {
t = new Image();
t.src = images[i];
}
}
};
this.reset = function() {
this.stop();
current = 0;
};
this.start = function() {
if(!timer) {
timer = setTimeout(anim ate, rate);
}
};
this.stop = function() {
if(timer) {
clearTimeout(ti mer);
timer = null;
}
};
}
A usage example:

var myImages = [],
i = 2,
n = 29,
myAnimation;

/* Define the array of images in the animation.
* It could be performed in any way, but this
* seems to suit your situation the best.
*/
while(i <= n) {
myImages[myImages.length] = i + '.jpg';
}

/* Create an Animation object. */
myAnimation = new Animation('righ t', myImages, 50);

/* If it was created properly, */
if(myAnimation) {
/* attempt to preload the frames */
myAnimation.pre load();
/* and start the animation when the document
* loads.
*/
window.onload = function() {
myAnimation.sta rt();
};
}

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
16129
by: Loony | last post by:
I have got a code like this in HTML section in ASP file which includes javascript file! The script works under MS IE but doesn't with Firefox! Can anybody tell me what is wrong? <HTML> <HEAD><TITLE></TITLE> <SCRIPT LANGUAGE="JavaScript" SRC="../inc/JSfile.js"><SCRIPT> <SCRIPT> <!-- other javascript scripts working propely
3
2953
by: niconedz | last post by:
Hi The following code works fine in IE but not Firefox. It's a little script that zooms an image and resizes the window to fit. Can anybody tell me what's wrong? Thanks Nico == btw.. sorry for the long post ==
17
2767
by: CES | last post by:
All, I was wondering if their is a way of loading an external script fill from within a script?? <script language="javascript" type="text/javascript"> function test(var){ <script language="javascript" src="../scripts/base.js" type="text/javascript" /> } </script> Obviously this would cause n error but this would give you an idea of what I'm looking to do. I know I can do this with a simple include but...
4
2152
by: petermichaux | last post by:
Hi, I'm hoping for a reason I'm wrong or an alternate solution... I'd like to be able to dynamically include some javascript files. This is like scriptaculous.js library but their solution is broken in Firefox 1.5.0.1 on OS X. What happens with the Scriptaculous library is this In the html document the author only has to include one line
2
3557
by: ranger7419 | last post by:
I'm trying to figure out why this script will work in IE 6 but not Firefox, and so I need someone here with a far better grasp on javascript to explain this. Basically, I have a page with several thumbnails. Above these thumbnails I placed a large picture with text next to it to describe what the picture is about. So, when you click a thumb, the large pic AND text change dynamically to reflect the thumbnail -- see...
15
5395
by: Lennart | last post by:
Hi folks, I have created an animated image gallery in dhtml. It works fine in Internet Explorer. In Firefox, it only works if I ommit the DOCTYPE tag. The page is valid xhtml-strict but with a xhtml1-strict DOCTYPE, I get a dead script and dozens of error messages like "Error in parsing value in property 'width'. Declaration dropped." on Line 0. This page doesn't work in Firefox but is valid xhtml:...
4
5933
by: aramsey | last post by:
I have a javascript program that works fine under Firefox and on IE when running XP, but is having a problem with IE running under Windows 2000 Pro. On my personal XP development machine I have the Microsoft Script Editor and I can set a breakpoint, step through code, inspect variables, etc... with no problem. On a machine where I am trying to debug this problem I am running Windows 2000 Pro with IE 6. I installed the Microsoft...
1
2385
by: tinnews | last post by:
I'm running a python script via the apache ExtFilterDefine directive, it works basically as expected *except* that when I change the script apache/firefox continue to run the old version of the python script until I remove the script completely and then replace it. I.e. my script is called tl2html.py, if I change it to (say) add several lines of output the added lines don't appear on firefox. I can restart firefox and I can restart...
2
3085
by: willyWEB66 | last post by:
Hi everyone, I have this code in javascript where the XML file is loaded and displayed to an html using XSLT. It works fine in IE but not in Firefox. My problem is in the looping to the childNodes. It seems that Firefox does not recognize this line of code >> xmlDoc.getElementsByTagName("urlValue").childNodes.nodeValue I'm not sure if this is the line that is not working, or the lines before it. I'm looping to the childNodes to compare to...
7
4032
by: mike57 | last post by:
The minimal AJAX script below works in Firefox, but not in IE, Opera, or Chrome. I could use some suggestions or referrals to resources that will help me get the script working in other browsers. Before there are six characters entered in the CAPTCHA code field, the 'Send' button is supposed to be disabled. When there are at least six characters in the CAPTCHA code field, the script attempts to verify the CAPTCHA w/AJAX. If it verifies, it...
0
8347
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8571
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7294
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.