By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,385 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,385 IT Pros & Developers. It's quick & easy.

loading script dynamically in Mozilla

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


Ola Fjelddahl wrote:
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
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.

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?
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.

[ ol***********@diespammers.mandator.com ]
/OF
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.