document.write and buffer data

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

    #1

    document.write and buffer data

    Hi

    It's very interesting problem. I couldn't even find any inforamtion
    about it on the google.
    I think that the best way of explain will be this simple example:

    <html>
    <body>
    <script language="JavaS cript" type="text/javascript"
    src="write.js"> </script>
    </body>
    </html>

    write.js:
    document.write( "start<br />\n");
    document.write( "<" + "script language='JavaS cript'
    type='text/javascript' src='test.js'>< " + "/script>");
    document.write( "end<br />\n");

    and test.js:
    document.write( 'middle <br />');


    The expected output is:
    start
    middle
    end

    but the real output is:
    start
    end
    middle

    This output has to be generated inside "write.js" file and I have to
    use sometimes some external files like this "test.js".
    I'm trying to find a solution to force a browser to output everything
    from test.js before the "end".

    I found only this info:
    A practical website valuation framework for owners who need a defensible range — a band with a confidence score, not a fake-precise number.

    where I found that placing HTML tag (without JavaScript) force a
    browser to output the buffer. But unfortuanetly I couldn't output any
    HTML tag inside write.js file.

    Is it possible to force a browser to render the content before "end"
    document.write?
  • McKirahan

    #2
    Re: document.write and buffer data

    "Radek Maciaszek" <radek.maciasze k@gmail.com> wrote in message
    news:39afc672.0 504010636.5ee68 8bc@posting.goo gle.com...[color=blue]
    > Hi
    >
    > It's very interesting problem. I couldn't even find any inforamtion
    > about it on the google.
    > I think that the best way of explain will be this simple example:
    >
    > <html>
    > <body>
    > <script language="JavaS cript" type="text/javascript"
    > src="write.js"> </script>
    > </body>
    > </html>
    >
    > write.js:
    > document.write( "start<br />\n");
    > document.write( "<" + "script language='JavaS cript'
    > type='text/javascript' src='test.js'>< " + "/script>");
    > document.write( "end<br />\n");
    >
    > and test.js:
    > document.write( 'middle <br />');
    >
    >
    > The expected output is:
    > start
    > middle
    > end
    >
    > but the real output is:
    > start
    > end
    > middle
    >
    > This output has to be generated inside "write.js" file and I have to
    > use sometimes some external files like this "test.js".
    > I'm trying to find a solution to force a browser to output everything
    > from test.js before the "end".
    >
    > I found only this info:
    > http://www.web-developer-india.com/w...t/refp_95.html
    > where I found that placing HTML tag (without JavaScript) force a
    > browser to output the buffer. But unfortuanetly I couldn't output any
    > HTML tag inside write.js file.
    >
    > Is it possible to force a browser to render the content before "end"
    > document.write?[/color]

    Is ASP an option?

    If so then you could use the FileSystemObjec t to merge the includes.


    Comment

    • Radek Maciaszek

      #3
      Re: document.write and buffer data

      "McKirahan" <News@McKirahan .com> wrote in message news:<RrydnUgMf JrdBNDfRVn-sQ@comcast.com> ...[color=blue]
      >
      > Is ASP an option?
      >
      > If so then you could use the FileSystemObjec t to merge the includes.[/color]

      I have PHP on server but unfortunately I couldn't use it in this case
      because HTML, write.js and test.js are on three different servers. So
      for example I could include "write.js" by PHP but I don't know if
      write.js return just a "document.write " or will try to include
      "test.js" or any other js file. And I couldn't change these
      requirements... So the only solution (IMO) is to force a browser to
      finish rendering everything before the "end" tag but there is no such
      possibility in pure JavaScript in IE nor in Mozilla. I hope I am
      wrong..

      Comment

      • Radek Maciaszek

        #4
        Re: document.write and buffer data

        With Ultimater help I've found a solution to this problem. Just fight
        a fire with a fire.

        document.write( "<script src='start.js'> \</script>");
        document.write( "<script src='test.js'>\ </script>");
        document.write( "<script src='end.js'>\</script>");

        here is the link:
        http://www.webdeveloper.com/forum/sh...ad.php?t=61386

        cheers
        Radek

        Comment

        • Evertjan.

          #5
          Re: document.write and buffer data

          Radek Maciaszek wrote on 04 apr 2005 in comp.lang.javas cript:[color=blue]
          > With Ultimater help I've found a solution to this problem.[/color]

          What problem?

          Without your quoting of the posting you are reacting on,
          how the hell should we know what you are talking about?



          --
          Evertjan.
          The Netherlands.
          (Replace all crosses with dots in my emailaddress)

          Comment

          • Radek Maciaszek

            #6
            Re: document.write and buffer data

            "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message news:<Xns962EC2 56CA5BFeejj99@1 94.109.133.29>. ..[color=blue]
            > Radek Maciaszek wrote on 04 apr 2005 in comp.lang.javas cript:[color=green]
            > > With Ultimater help I've found a solution to this problem.[/color]
            >
            > What problem?
            >
            > Without your quoting of the posting you are reacting on,
            > how the hell should we know what you are talking about?[/color]

            I'm sorry. I just didn't want to quote all the long post. But if you
            go to this link: http://www.webdeveloper.com/forum/sh...ad.php?t=61386
            you will find the problem and the answer :)

            cheers
            Radek

            Comment

            • Evertjan.

              #7
              Re: document.write and buffer data

              Radek Maciaszek wrote on 05 apr 2005 in comp.lang.javas cript:
              [color=blue]
              > "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
              > news:<Xns962EC2 56CA5BFeejj99@1 94.109.133.29>. ..[color=green]
              >> Radek Maciaszek wrote on 04 apr 2005 in comp.lang.javas cript:[color=darkred]
              >> > With Ultimater help I've found a solution to this problem.[/color]
              >>
              >> What problem?
              >>
              >> Without your quoting of the posting you are reacting on,
              >> how the hell should we know what you are talking about?[/color]
              >
              > I'm sorry. I just didn't want to quote all the long post. But if you
              > go to this link:
              > http://www.webdeveloper.com/forum/sh...ad.php?t=61386 you will find
              > the problem and the answer :)[/color]

              This is usenet, so please conform to usenet practices, Radek.

              Don't make us use a newbie technology like the web for that.

              --
              Evertjan.
              The Netherlands.
              (Replace all crosses with dots in my emailaddress)

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: document.write and buffer data

                Radek Maciaszek wrote:
                [color=blue]
                > document.write( "<script src='start.js'> \</script>");
                > document.write( "<script src='test.js'>\ </script>");
                > document.write( "<script src='end.js'>\</script>");[/color]

                Firstly, don't call document.write( ) consecutively if you can avoid it.
                Doing otherwise is known to be error-prone, and inefficient compared to
                the alternative(s).

                Secondly, you don't have to escape the `<' character, but you should escape
                the `</' (ETAGO delimiter) with `<\/' if these statements are part of a
                HTML document (note that document.write( ) is not supposed to work in XHTML,
                you have to use W3C DOM Level 2+ Methods there).

                Thirdly, your `script' elements are lacking the `type' attribute, required
                for Valid (X)HTML 4.01/1.0+.

                Use instead:

                var
                scripts = new Array("start.js ", "test.js", "end.js"),
                s = "";

                for (var i = 0; i < scripts.length; i++)
                {
                s += '<script type="text/javascript" src="'
                + scripts[i]
                + '"><\/script>\n';
                }

                document.write( s);

                However, note that your method using `scripts' element alone may not work
                as expected. But if you concatenate the output strings to be generated,
                your original problem should disappear. Yet, making your document dependent
                on client-side scripting this way, could raise usability issues, depending
                on the expected environment it should run.
                [color=blue]
                > here is the link:
                > http://www.webdeveloper.com/forum/sh...ad.php?t=61386[/color]

                Alas, there are no competent people there. Not a surprise to me, though.


                PointedEars
                --
                Das Netz ist Freude. Es ist Ekstase, die jeden einzelnen Nerv erglühen
                läßt. Es ist Duft, den man fühlt. Es ist ein Bild, das man riecht. Es
                ist Erfüllung - ein Geschmack, neben dem alles andere schal ist.
                -- "Netzreiter-Preisung" aus "Der Netzparasit" von Andreas Brandhorst

                Comment

                • Kevin Yarmak

                  #9
                  Re: document.write and buffer data

                  It doesn't matter where you break your End Script tags.

                  The left-than-character doesn't need to be escaped, but neither does the
                  forward-slash.

                  document.write( "<script src='start.js'> \</script>");
                  is the same as:
                  document.write( "<script src='start.js'> <\/script>");

                  You Simply cannot Write it out: </script> or you will actually end the
                  "real" SCRIPT tag.


                  Yeah, the script tags are lacking the TYPE attribute...
                  They are also lacking the LANGUAGE attribute.
                  Even though the LANGUAGE attribute is deprecated in the newer browsers,
                  it doesn't mean that older browsers don't still use it, because they do.
                  It's best to include both of the attributes.
                  (note: deprecated means that it is no longer supported and kinda
                  abandoned)
                  Thus:
                  document.write( "<script type="text/javascript" language="javas cript"
                  src='start.js'> \</script>");

                  *** Sent via Developersdex http://www.developersdex.com ***

                  Comment

                  • Michael Winter

                    #10
                    Re: document.write and buffer data

                    Kevin Yarmak wrote:
                    [color=blue]
                    > It doesn't matter where you break your End Script tags.[/color]

                    Yes, it does.

                    [snip]
                    [color=blue]
                    > document.write( "<script src='start.js'> \</script>");
                    > is the same as:
                    > document.write( "<script src='start.js'> <\/script>");[/color]

                    In so far as an ECMAScript parser is concerned, yes, but not from the
                    point of view of an SGML parser. The HTML specification states that a
                    user agent is permitted to terminate a SCRIPT element on the first
                    occurance of ETAGO (</). Even though no-one knows of a user agent that
                    does this, breaking this token with a backslash will prevent markup
                    validators from issuing errors on every occurance.

                    Of course, if you place the script in an external file, which is surely
                    where the bulk of any script should go in most cases, how an SGML parser
                    behaves is of no consequence; no escaping is required at all.

                    [snip]
                    [color=blue]
                    > They are also lacking the LANGUAGE attribute.
                    > Even though the LANGUAGE attribute is deprecated in the newer browsers,
                    > it doesn't mean that older browsers don't still use it, because they do.[/color]

                    Not in any way that is really desirable or necessary.
                    [color=blue]
                    > It's best to include both of the attributes.[/color]

                    I strongly disagree.

                    [snip]

                    Mike

                    --
                    Michael Winter
                    Replace ".invalid" with ".uk" to reply by e-mail.

                    Comment

                    • Kevin Yarmak

                      #11
                      Re: document.write and buffer data

                      If an older browser "sees" the TYPE attribute, it ignores it.
                      If a newer broswer "sees" the LANGUAGE attribute, it also ignores it.

                      You can provide as many illegal attributes in any HTML tag as you like!

                      example:

                      <input id="blah" bbfgbbb="Hello World!">
                      <script id="scriptId" megaId="custom id"></script>
                      <script type="text/javascript" language="javas cript"><!--
                      alert(document. getElementById( "blah").bbfgbbb )
                      alert(document. getElementById( "scriptId").meg aId)
                      //--></script>

                      My conclusion is that the LANGUAGE attribute still servers a purpose --
                      for older browers.
                      You never know, maybe one outta a hundred of the guests to your website
                      will have an old browser.
                      It may be extra typing to also include the LANGUAGE attribute but it
                      does still serve a purpose -- these older browers.
                      It can't hurt to include the LANGUAGE attribue because it's not gonna
                      cause any browers to mis-behave.

                      *** Sent via Developersdex http://www.developersdex.com ***

                      Comment

                      • Lee

                        #12
                        Re: document.write and buffer data

                        Kevin Yarmak said:
                        [color=blue]
                        >My conclusion is that the LANGUAGE attribute still servers a purpose --
                        >for older browers.
                        >You never know, maybe one outta a hundred of the guests to your website
                        >will have an old browser.[/color]

                        And what percentage of the browsers that don't understand
                        type="text/javascript" are going to understand all of your
                        code? Would it be better for them to not try to execute it?

                        Comment

                        • Thomas 'PointedEars' Lahn

                          #13
                          Re: document.write and buffer data

                          Kevin Yarmak wrote:
                          [color=blue]
                          > If an older browser "sees" the TYPE attribute, it ignores it.[/color]

                          Most certainly.
                          [color=blue]
                          > If a newer broswer "sees" the LANGUAGE attribute, it also ignores it.[/color]

                          No.
                          [color=blue]
                          > You can provide as many illegal attributes in any HTML tag as you like![/color]

                          There is nothing like "illegal" attributes. Either a document conforms to
                          a HTML specification or it does not. Either it is Valid HTML or it is no
                          HTML at all. BTW: HTML parsing is not restricted to Web browsers, and even
                          then there are a user agents out there that use strict SGML parsers.
                          [color=blue]
                          > example:
                          >
                          > <input id="blah" bbfgbbb="Hello World!">
                          > <script id="scriptId" megaId="custom id"></script>[/color]

                          The `script' element does not have a `megaId' attribute, this is invalid
                          HTML, i.e. *no* HTML. Tagsoup parsers will silently ignore it, SGML
                          parsers will yield an error and are allowed to display nothing else but
                          the error.
                          [color=blue]
                          > <script type="text/javascript" language="javas cript">[/color]

                          This can be included in Valid HTML 4.01 Transitional only.
                          [color=blue]
                          > <!--[/color]

                          Scripts do not need to/should not be commented out this way any longer.
                          [color=blue]
                          > alert(document. getElementById( "blah").bbfgbbb )
                          > alert(document. getElementById( "scriptId").meg aId)[/color]

                          Although this is a test case, note that this kind of referring to
                          objects is known to be error-prone and therefore not recommended.

                          <http://pointedears.de/scripts/test/whatami>
                          [color=blue]
                          > //--></script>
                          >
                          > My conclusion is that the LANGUAGE attribute still servers a purpose --
                          > for older browers.[/color]

                          You are mistaken. language="JavaS cript1.2" affects Mozilla's behavior,
                          that's all.
                          [color=blue]
                          > You never know, maybe one outta a hundred of the guests to your website
                          > will have an old browser.[/color]

                          A browser older than 10 (in words: TEN!) years?
                          [color=blue]
                          > It may be extra typing to also include the LANGUAGE attribute but it
                          > does still serve a purpose -- these older browers.[/color]

                          No, it does not. Those older browsers do not need that attribute, as you
                          have correctly stated above. It is because there is no HTML specification
                          or UA reference that says that the attribute must be included and no
                          ECMAScript specification that says the value of that has to be "javascript "
                          and the like for the script to be executed by a JavaScript/ECMAScript
                          conforming script engine.
                          [color=blue]
                          > It can't hurt to include the LANGUAGE attribue because it's not gonna
                          > cause any browers to mis-behave.[/color]

                          It can hurt if you use a Strict document type or XHTML 1.1+. It is simply
                          Voodoo: You know that it most certainly changes nothing but you include it
                          anyway, wasting your time and disk space and the time and bandwidth of your
                          visitors whose user agents have to download, parse and error-correct it.
                          [color=blue]
                          > *** Sent via Developersdex http://www.developersdex.com ***[/color]

                          Of course. Lots of Voodoo coding originates at this source.


                          PointedEars
                          --
                          "Auf dieser Seite finden Sie Tip's, Trick's und Link's zu Handy's von
                          verschiedener Hersteller" -- Ich glaube, damit ist hinlänglich bewiesen,
                          daß die Funkstrahlen von Handys schädlich fürs Gehirn sind.
                          (g'f'nd'n ''f http://members.aol.com/apostrophs/apostrophen.htm)

                          Comment

                          Working...