Conditional loading of a remote script using document.write ... or?

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

    #1

    Conditional loading of a remote script using document.write ... or?

    I need to be able to conditionally load a remote script, using
    the "<script src=..." syntax. Or some other way. I've seen
    people writing about using the document.write method, but it's
    not working like I want it to.

    What's happening is, if I do a document.write( scriptcall), the
    script loads, although sometimes very slowly... (?). Any inline
    code is executed (I used an alert to verify that the script is
    loading). But all the previous content of the page goes 'poof'.

    If I look at the source of the page in this state, all I see
    is the script tag I've document.writte n. I've tried using
    document.close after writing the tag, and not using it, but
    the results are the same. A blank page.

    Wish there was a "loadscript(src )" function I could use.

    Anybody know how to do what I want to do?
  • Ivo

    #2
    Re: Conditional loading of a remote script using document.write ... or?

    "Razzbar" wrote[color=blue]
    > I need to be able to conditionally load a remote script, using
    > the "<script src=..." syntax. Or some other way.[/color]

    That syntax would not be reliable in a contional way. Try this:

    if ( foo ) {
    var bar = document.create Element('script ');
    bar.src = 'mypath/myscript.js';
    }
    [color=blue]
    > I've seen people writing about using the document.write
    > method, but it's not working like I want it to.
    > If I look at the source of the page in this state, all I see
    > is the script tag I've document.writte n.[/color]

    document.write( ) should only be used during the initial load of the page, if
    at all. Upon loading, the document is closed and writing to it would result
    in a new document being generated. This is what you see in the source.
    HTH
    Ivo


    Comment

    • Razzbar

      #3
      Re: Conditional loading of a remote script using document.write ... or?

      "Ivo" <no@thank.you > wrote in message news:<40944b09$ 0$12756$4a44175 0@news.wanadoo. nl>...[color=blue]
      > "Razzbar" wrote[color=green]
      > > I need to be able to conditionally load a remote script, using
      > > the "<script src=..." syntax. Or some other way.[/color]
      >
      > That syntax would not be reliable in a contional way. Try this:
      >
      > if ( foo ) {
      > var bar = document.create Element('script ');
      > bar.src = 'mypath/myscript.js';[/color]
      document.body.a ppendChild(bar) ;[color=blue]
      > }[/color]

      Thank you! It didn't work, but I added the appendChild line,
      and it's all hunky-dory.


      [color=blue]
      >[color=green]
      > > I've seen people writing about using the document.write[/color][/color]
      [color=blue]
      > document.write( ) should only be used during the initial load of the page, if[/color]

      Besides, I think it's just a hokey kludgey way to do things. IMHO.
      [color=blue]
      > at all. Upon loading, the document is closed and writing to it would result
      > in a new document being generated. This is what you see in the source.[/color]

      Exactly. It takes forever, then you see a blank page. Worst, you can't
      reload the original page. Even with a pragma no-cache, if you reload
      you get the .js file. You just can't get the original page back -- in
      IE6. Probably browser specific. Too much of that going around.




      [color=blue]
      > HTH[/color]

      You did. Thanks.

      Comment

      • Csaba Gabor

        #4
        Re: Conditional loading of a remote script using document.write ... or?

        However, regarding loading of script by setting .src,
        see the comments regarding Mozilla / Netscape at


        Csaba Gabor

        "Razzbar" <glakk@potatora dio.f2s.com> wrote in message
        news:c48470fc.0 405041254.6e931 5c8@posting.goo gle.com...[color=blue]
        > "Ivo" <no@thank.you > wrote in message[/color]
        news:<40944b09$ 0$12756$4a44175 0@news.wanadoo. nl>...[color=blue][color=green]
        > > "Razzbar" wrote[color=darkred]
        > > > I need to be able to conditionally load a remote script, using
        > > > the "<script src=..." syntax. Or some other way.[/color]
        > >
        > > That syntax would not be reliable in a contional way. Try this:
        > >
        > > if ( foo ) {
        > > var bar = document.create Element('script ');
        > > bar.src = 'mypath/myscript.js';[/color]
        > document.body.a ppendChild(bar) ;[color=green]
        > > }[/color]
        >
        > Thank you! It didn't work, but I added the appendChild line,
        > and it's all hunky-dory.
        >
        >
        >[color=green]
        > >[color=darkred]
        > > > I've seen people writing about using the document.write[/color][/color]
        >[color=green]
        > > document.write( ) should only be used during the initial load of the[/color][/color]
        page, if[color=blue]
        >
        > Besides, I think it's just a hokey kludgey way to do things. IMHO.
        >[color=green]
        > > at all. Upon loading, the document is closed and writing to it would[/color][/color]
        result[color=blue][color=green]
        > > in a new document being generated. This is what you see in the source.[/color]
        >
        > Exactly. It takes forever, then you see a blank page. Worst, you can't
        > reload the original page. Even with a pragma no-cache, if you reload
        > you get the .js file. You just can't get the original page back -- in
        > IE6. Probably browser specific. Too much of that going around.
        >
        >
        >
        >
        >[color=green]
        > > HTH[/color]
        >
        > You did. Thanks.[/color]


        Comment

        • Ivo

          #5
          Re: Conditional loading of a remote script using document.write ... or?

          "Csaba Gabor" pointed out:[color=blue]
          > However, regarding loading of script by setting .src,
          > see the comments regarding Mozilla / Netscape at
          > http://groups.google.com/groups?thre...eda.datanet.hu[/color]

          The discussion in that thread is about a changing the source of an already
          existing script while this one was about setting the source of a newly
          created script. Even those browsers see a difference in that.
          Ivo


          Comment

          Working...