Dynamic include?

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

    Dynamic include?

    Hey hey hey :)

    I'd like to do a .js include each X seconds, to update an array (the .js is
    really a .php file which generates the javascript dynamically).

    Just like <script language="JavaS cript" src="..., but in something like a
    function call, e.g. "include('mydyn amicscript.js') ;".

    Can be done? Yes? No?

    TIA,
    Daniel :)


    --
    Why do cats jump out of windows? Because there's love out there!
  • nj

    #2
    Re: Dynamic include?

    Yep, it's possible.

    One way to do this is by giving a script tag an ID, and then use a
    timeout to reload the script by altering, or setting the SRC attribute
    of the script tag.

    Something like this (completely ad hoc and untested) might do the
    trick:

    -------

    <script language="javas cript" src="somejscode .php"
    id="somejscode" ></script>
    <script language="javas cript">

    function refreshScript() {
    // if this doesn't work (due to browser caching for instance), try
    adding a random querystring parameter to force a refresh
    document.getEle mentById("somej scode").src = "somejscode.php ";
    }

    setInterval ("refreshScript ();", 5000); // refresh in 5 seconds

    </script>

    -------


    hope this helps,
    J.

    Comment

    • DanielEKFA

      #3
      Re: Dynamic include?

      nj wrote:
      [color=blue]
      > Yep, it's possible.
      >
      > One way to do this is by giving a script tag an ID, and then use a
      > timeout to reload the script by altering, or setting the SRC attribute
      > of the script tag.
      >
      > Something like this (completely ad hoc and untested) might do the
      > trick:
      >
      > -------
      >
      > <script language="javas cript" src="somejscode .php"
      > id="somejscode" ></script>
      > <script language="javas cript">
      >
      > function refreshScript() {
      > // if this doesn't work (due to browser caching for instance), try
      > adding a random querystring parameter to force a refresh
      > document.getEle mentById("somej scode").src = "somejscode.php ";
      > }
      >
      > setInterval ("refreshScript ();", 5000); // refresh in 5 seconds
      >
      > </script>
      >
      > -------
      >
      >
      > hope this helps,
      > J.[/color]

      Hi NJ :)

      Thanks for the reply. Unfortunately, this doesn't work, with our without
      adding a bogus variable to the URL (at least not in Firefox). In the
      meantime I was fiddling around with loading a helper.html file in an
      iframe, and letting the helper page update the script (actually the script
      creates an array), then call back to the parent page with the updated
      array. This should work, but firefox doesn't really like it
      ("document.getE lementById('hel per').location has no properties" or
      "document.frame s has no properties")... Gonna kick on that for a bit...

      Cheers,
      Daniel :)

      --
      Why do cats jump out of windows? Because there's love out there!

      Comment

      • DanielEKFA

        #4
        Re: Dynamic include?

        DanielEKFA wrote:
        [color=blue]
        > array. This should work, but firefox doesn't really like it
        > ("document.getE lementById('hel per').location has no properties" or
        > "document.frame s has no properties")... Gonna kick on that for a bit...
        >[/color]

        Of course I was just forgetful, it's .src, not .location.href :) Works fine
        now.


        --
        Why do cats jump out of windows? Because there's love out there!

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Dynamic include?

          nj wrote:
          [color=blue]
          > Yep, it's possible.
          >
          > One way to do this is by giving a script tag an ID, and then use a timeout
          > to reload the script by altering, or setting the SRC attribute of the
          > script tag.[/color]

          You mean the `script' ([X]HTML) element which consists of a start tag
          (`<script ...>'), content that may be empty and an end tag (`</script>').
          [color=blue]
          > Something like this (completely ad hoc and untested) might do the
          > trick:
          >
          > -------
          >
          > <script language="javas cript" src="somejscode .php"
          > id="somejscode" ></script>[/color]

          The `script' element does not have an `id' attribute in HTML, and
          since the `type' attribute is missing here this is not even HTML:
          The above is not supposed to work.


          PointedEars
          --
          Immerhin weiß ich, daß die durchschnittlic he Verkaufsperson kein Abitur
          erlitten hat, somit der Sprachwitz bisweilen nicht durch entsprechende
          Sachkenntnis gedämpft ist.
          -- Martin Gerdes in desd <qr1p5vcdiiag01 774vu3jh56nb6l8 6acn5@4ax.com>

          Comment

          • Randy Webb

            #6
            Re: Dynamic include?

            Thomas 'PointedEars' Lahn wrote in a message on 07 May 2005 in reply to
            a message dated 21 April 2005 and for some reason felt it appropriate to
            reply to a message that was dead and gone for over two weeks and babbled
            incoherently as follows:
            [color=blue]
            > nj wrote:
            >
            >[color=green]
            >>Yep, it's possible.
            >>
            >>One way to do this is by giving a script tag an ID, and then use a timeout
            >>to reload the script by altering, or setting the SRC attribute of the
            >>script tag.[/color]
            >
            >
            > You mean the `script' ([X]HTML) element which consists of a start tag
            > (`<script ...>'), content that may be empty and an end tag (`</script>').[/color]

            Who said anything about [X]HTML?
            [color=blue][color=green]
            >>Something like this (completely ad hoc and untested) might do the
            >>trick:
            >>
            >>-------
            >>
            >><script language="javas cript" src="somejscode .php"
            >>id="somejscod e"></script>[/color]
            >
            >
            > The `script' element does not have an `id' attribute in HTML, and
            > since the `type' attribute is missing here this is not even HTML:[/color]

            Again, who said anything about [X]HTML? For all you know it could be an
            ..hta application. Besides, you missed the very important point that
            changing the source of a script tag only works in IE. For other
            browsers/UA's you have to implement a different strategy.
            [color=blue]
            > The above is not supposed to work.[/color]

            That depends, directly, on your definition of "works". Perhaps if you
            bothered to learn what reality is in the world of browsers/UA's you
            would realize it does indeed "work" in certain scenarios.

            --
            Randy
            comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

            Comment

            Working...