loading script dynamically in Mozilla

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ola Fjelddahl

    #1

    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.create Element("SCRIPT ");
    oElement.id = "myscriptid ";
    oElement.src = "scripts/common.js";
    document.body.a ppendChild(oEle ment);
    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
  • Martin Honnen

    #2
    Re: loading script dynamically in Mozilla



    Ola Fjelddahl wrote:
    [color=blue]
    > 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.create Element("SCRIPT ");
    > oElement.id = "myscriptid ";
    > oElement.src = "scripts/common.js";
    > document.body.a ppendChild(oEle ment);
    > And then I call a function in the file by just calling
    > myTestFunction( );[/color]

    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.
    [color=blue]
    > 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.[/color]

    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/

    Comment

    • Ola Fjelddahl

      #3
      Re: loading script dynamically in Mozilla

      hi.

      Thanks for answering.

      Inline.

      [color=blue][color=green]
      > > 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.create Element("SCRIPT ");
      > > oElement.id = "myscriptid ";
      > > oElement.src = "scripts/common.js";
      > > document.body.a ppendChild(oEle ment);
      > > And then I call a function in the file by just calling
      > > myTestFunction( );[/color][/color]
      [color=blue]
      > 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.[/color]

      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.

      [color=blue][color=green]
      > > 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.[/color][/color]
      [color=blue]
      > What does "fail" mean, do you get a script error when calling
      > myTestFunction?[/color]

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

      [color=blue]
      > 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.[/color]

      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.

      [ ola.fjelddahl@d iespammers.mand ator.com ]
      /OF

      Comment

      Working...