Array handling in Mozilla/Firefox

E

ekimnosnews

I'm programming a JS tile map editor for my friend's game. The map
editor has different "sections" that contain different tiles. The way
that it works is when you select a section it calls a JS function that
changes the src of a script tag that contains the array of tiles for
that section, then reloads the tile selection table. This works great
in IE, but Mozilla/Firefox doesn't update the array when I switch JS
files. I've tried putting a function in the JS file that would be
called when the file is switched, but this doesn't work either, so I
think that Moz/FF caches arrays when the page loads. Any ideas?
 
M

Martin Honnen

The way
that it works is when you select a section it calls a JS function that
changes the src of a script tag that contains the array of tiles for
that section, then reloads the tile selection table. This works great
in IE, but Mozilla/Firefox doesn't update the array when I switch JS
files. I've tried putting a function in the JS file that would be
called when the file is switched, but this doesn't work either, so I
think that Moz/FF caches arrays when the page loads. Any ideas?

Mozilla doesn't load a new script if you change the src of a <script>
element, you need to create a new <script> element, set its src and then
insert the element into the page if you want to load a new script. Also
note that loading might happen asynchronously so that you need to attach
an event listener to the load event.
Here is an example made in response to a post some days ago in the
Mozilla DOM newsgroup:
http://home.arcor.de/martin.honnen/javascript/200407/test20040701.html
That has been tested to work with Netscape 7.1 and Firefox 0.9.
Loading scripts dynamically doesn't work with older Mozilla version but
I can't tell the exact version it was implemented, do some tests
yourself if you want to rely on that feature.
 
R

Randy Webb

Here is an example made in response to a post some days ago in the
Mozilla DOM newsgroup:
http://home.arcor.de/martin.honnen/javascript/200407/test20040701.html
That has been tested to work with Netscape 7.1 and Firefox 0.9.
Loading scripts dynamically doesn't work with older Mozilla version but
I can't tell the exact version it was implemented, do some tests
yourself if you want to rely on that feature.

The title says IE5.5/6.0 Win but I do not get the loaded alert in IE6.0
on WinME.

I saved it locally, added my own JS file with an alert, and I get the
alert from the .js file, just not from the .html page.
 
M

Martin Honnen

Randy said:
Martin Honnen wrote:


The title says IE5.5/6.0 Win but I do not get the loaded alert in IE6.0
on WinME.

Sorry for the confusion, in the other newsgroup the guy asked how to do
it with Mozilla/Netscape, I then intended to write a cross browser (well
IE and Mozilla and any other browser firing load or onreadystate events)
way using an event handler thus I gave it that title but in that thread
http://groups.google.com/groups?hl=...up:*mozilla*dom*&hl=en&lr=&ie=UTF-8&scoring=d
I mainly focussed on a Mozilla solution and didn't look further why IE
refuses to fire the event handler.
I might look into that later.
 
M

Martin Honnen

Randy said:
Martin Honnen wrote:


The title says IE5.5/6.0 Win but I do not get the loaded alert in IE6.0
on WinME.

I have now looked into that and as tested with IE6 here the onreadystate
event is fired but unfortunately the sequence of readyState values is
different on different occasions, it doesn't always reach the readyState
value 'complete' that the above page checks for but sometimes stops with
the readyState value 'loaded'. It seems to depend on whether the script
file is loaded from cache or not, at least that is one influencing
factor I could determine.
If the script is changed to check the variable when
readyState == 'loaded' || readyState == 'complete'
then at least with that short script file the variable is always defined
so for the time being I have made the following test case:
http://home.arcor.de/martin.honnen/javascript/200407/test2004070401.html
that seems to solve the problem for IE5.5/6 on Windows.
 

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
474,472
Messages
2,571,834
Members
48,802
Latest member
shadowoftheunknown
Top