loading script dynamically in Mozilla

O

Ola Fjelddahl

hi.

I load a script dynamically and it works
* everytime with IE6.
* sometimes! with Mozilla1.5 <- makes me curious
* never with Opera7.11
all tests on WindowsXP.

With "sometimes" I mean
[reload->fail][reload->fail][reload->succeed][reload->fail][reload->fail][reload->fail][reload-succceed][reload->fail]
etc. until it sometimes loops.

How I do:
In the page I call:
var oElement = document.createElement("SCRIPT");
oElement.id = "myscriptid";
oElement.src = "scripts/common.js";
document.body.appendChild(oElement);
And then I call a function in the file by just calling
myTestFunction();

I can live with that it works or not works but not Sometimes in
Mozilla! (Also: the myTestFunction just contains an alert and
sometimes this one starts to loop so I have to shoot down Mozilla.

TIA

/OF
 
M

Martin Honnen

Ola said:
I load a script dynamically and it works
* everytime with IE6.
* sometimes! with Mozilla1.5 <- makes me curious
* never with Opera7.11
all tests on WindowsXP.

With "sometimes" I mean
[reload->fail][reload->fail][reload->succeed][reload->fail][reload->fail][reload->fail][reload-succceed][reload->fail]
etc. until it sometimes loops.

How I do:
In the page I call:
var oElement = document.createElement("SCRIPT");
oElement.id = "myscriptid";
oElement.src = "scripts/common.js";
document.body.appendChild(oElement);
And then I call a function in the file by just calling
myTestFunction();

There is no guarantee that the browser waits till the file common.js is
loaded and parsed before it process the next line with
myTestFunction()
so that could be a reason for the error.
I can live with that it works or not works but not Sometimes in
Mozilla! (Also: the myTestFunction just contains an alert and
sometimes this one starts to loop so I have to shoot down Mozilla.

What does "fail" mean, do you get a script error when calling
myTestFunction?

An alert is a modal dialog that blocks the browser thus it is not a good
tool if you want to debug things that happen repeatedly.
Let the function output some text to the page (a textarea or use the DOM
to add some text) and the problem might go away.
 
O

Ola Fjelddahl

hi.

Thanks for answering.

Inline.

I load a script dynamically and it works
* everytime with IE6.
* sometimes! with Mozilla1.5 <- makes me curious
* never with Opera7.11
all tests on WindowsXP.
With "sometimes" I mean
[reload->fail][reload->fail][reload->succeed][reload->fail]
[reload->fail][reload->fail][reload->fail][reload->succeed]
[reload->fail]
etc. until it sometimes loops.
How I do:
In the page I call:
var oElement = document.createElement("SCRIPT");
oElement.id = "myscriptid";
oElement.src = "scripts/common.js";
document.body.appendChild(oElement);
And then I call a function in the file by just calling
myTestFunction();
There is no guarantee that the browser waits till the file common.js is
loaded and parsed before it process the next line with
myTestFunction()
so that could be a reason for the error.

I have tried both running them (loading js-file and calling) both
after each other and with a delay. Say I have a button for calling
the function; first I load the page and then I wait a second and then
I call the function by pressing the button. Sometimes works,
sometimes not.
So I don't believe it has to do with the time for loading the script
file.

I havn't found a way to retrieve the text for dynamically added
scripts either.

What does "fail" mean, do you get a script error when calling
myTestFunction?

Right. The function does not exist.
And by looping I mean that the messagebox popus up again as soon as i
click it away.

An alert is a modal dialog that blocks the browser thus it is not a good
tool if you want to debug things that happen repeatedly.
Let the function output some text to the page (a textarea or use the DOM
to add some text) and the problem might go away.

Tried that too. Great advice though.


I have come to suspect that there is a bug in Mozilla (never thought I
would write that in a public forum and still don't) due to the
irregular behaviour.
But since Opera won't ever work I have decided on a less sexy
solution.

If there are any Mozilla coders out there, please throw me a line and
I will see if I can make a small page to repeat the behaviour.

[ (e-mail address removed) ]
/OF
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top