Array handling in Mozilla/Firefox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ekimnosnews@hotmail.com

    Array handling in Mozilla/Firefox

    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?

  • Martin Honnen

    #2
    Re: Array handling in Mozilla/Firefox



    ekimnosnews@hot mail.com wrote:
    [color=blue]
    > 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?[/color]

    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:

    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.

    --

    Martin Honnen


    Comment

    • Randy Webb

      #3
      Re: Array handling in Mozilla/Firefox

      Martin Honnen wrote:[color=blue]
      >
      >[/color]

      <--snip-->
      [color=blue]
      > Here is an example made in response to a post some days ago in the
      > Mozilla DOM newsgroup:
      > http://home.arcor.de/martin.honnen/j...t20040701.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.[/color]

      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.


      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ - http://jibbering.com/faq/

      Comment

      • Martin Honnen

        #4
        Re: Array handling in Mozilla/Firefox



        Randy Webb wrote:
        [color=blue]
        > Martin Honnen wrote:[/color]
        [color=blue]
        >[color=green]
        >> Here is an example made in response to a post some days ago in the
        >> Mozilla DOM newsgroup:
        >> http://home.arcor.de/martin.honnen/j...t20040701.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.[/color]
        >
        >
        > The title says IE5.5/6.0 Win but I do not get the loaded alert in IE6.0
        > on WinME.[/color]

        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

        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.

        --

        Martin Honnen


        Comment

        • Martin Honnen

          #5
          Re: Array handling in Mozilla/Firefox



          Randy Webb wrote:
          [color=blue]
          > Martin Honnen wrote:[/color]
          [color=blue]
          >[color=green]
          >> Here is an example made in response to a post some days ago in the
          >> Mozilla DOM newsgroup:
          >> http://home.arcor.de/martin.honnen/j...t20040701.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.[/color]
          >
          >
          > The title says IE5.5/6.0 Win but I do not get the loaded alert in IE6.0
          > on WinME.[/color]

          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:

          that seems to solve the problem for IE5.5/6 on Windows.

          --

          Martin Honnen


          Comment

          Working...