473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

loading script dynamically in Mozilla

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
2 2185


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David | last post by:
Hi, I use the following page code to open a popup window - it works OK, but whilst the popup is loading you can see the URL in the title of the popup until it's fully loaded and then the title...
11
by: Wentink | last post by:
Does anybody have a simple script that let's me popup a picture from a thumbnail? The ones i found are all very very complicated and messy in the source... Thanks, Tintin
10
by: Randy Webb | last post by:
This page: http://www.hikksworld.com/loadJSFiles/ Is one where I was testing the ability of browsers that can/can't dynamically load a JS file with one of the three methods: 1)Changing the src...
5
by: danny.myint | last post by:
I was under the assumption that javascript loads all the <head></head> elements before processing the <body> tag in Mozilla/Netscape/Firefox. It doesn't seem like it, with my problem. I have...
7
by: cjl | last post by:
Hey all: I've searched the newsgroup, and googled, but I'm stuck. I want to be able to 'dynamically' add a .js file to a web page after the page has loaded, based on user interaction. For...
17
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...
1
by: ozzy.osborn | last post by:
Hello All, I have been struggling with a cross browser solution to loading external javascript files on the fly. I have been successful using the following code in IE6: var newScr =...
2
by: boczek | last post by:
Hello all. I'm writing a small async webapp. in JavaScript and I'm using <script> element technique to load data. I'm usign <scriptbecause of cross domain restrictions with XmlRequest. The...
5
by: Pete Marsh | last post by:
Wondering if anyone can recomend some sample code for dynamically loading the GD module. I have tried setting the extension dir in php.ini, and loading the GD module from there when apache is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.