javascript generated html

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

    #1

    javascript generated html

    Suppose I download a html file with javascript in it, for example,

    <html>
    <body>
    <script language="JavaS cript">
    document.write( "Hello");
    </script>
    </body>
    </html>

    How can I translate that to pure html,

    <html>
    <body>
    Hello
    </body>
    </html>

    I am looking for a c++ solution.

    Thanks,

    qk
  • Lasse Reichstein Nielsen

    #2
    Re: javascript generated html

    quikquic@yahoo. com (quikquic@yahoo .com) writes:
    [color=blue]
    > Suppose I download a html file with javascript in it, for example,[/color]
    ....[color=blue]
    > <script language="JavaS cript">
    > document.write( "Hello");
    > </script>[/color]
    ....[color=blue]
    > How can I translate that to pure html,[/color]
    ....[color=blue]
    > Hello[/color]
    ....

    In this, simple, case it is fairly easy. Remove the script tags and
    change calls to document.write into its value. But that only works when
    all the script element contains are calls to document.write.

    If the Javascript is more complicated, you will have to execute it to
    know what it does. The simplest solution would be to load a browser
    and put the page into it, and then extract the generated HTML.
    Otherwise, you will need an implementation of Javscript and a runtime
    environment similar ot that provided by a browser in order to execute
    the code correctly.

    If you are aiming for the Windows platform, You can probably remotely
    control IE, or make an instance of the HTML rendering widget, and put
    the code into it. When (or if) it finishes parsing the page, including
    the embedded Javascript, you can use
    document.docume ntElement.inner HTML to get the contents of the
    resulting page's html element.

    If you are using this for anything critical, and the user supplies the
    page, then they can make pages where the Javascript never finishes
    executing. A simple "while(true ){}" can do it, but you can check in
    advance whether a script will loop forever or not, it can always be
    disguised to fool your check. You will have to time-out the browser
    if it runs for too long.

    You will also be open to any security bugs in IE.
    <URL:http://www.pivx.com/larholm/unpatched/>

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Jerry Coffin

      #3
      Re: javascript generated html

      In article <ead1f717.03091 81530.13f2d2da@ posting.google. com>,
      quikquic@yahoo. com says...[color=blue]
      > Suppose I download a html file with javascript in it, for example,
      >
      > <html>
      > <body>
      > <script language="JavaS cript">
      > document.write( "Hello");
      > </script>
      > </body>
      > </html>
      >
      > How can I translate that to pure html,[/color]

      In any more than a trivial case like this, you can't -- the primary
      reason people use Javascript in the first place is to do things that are
      impossible or thoroughly unreasonable using HTML.

      --
      Later,
      Jerry.

      The universe is a figment of its own imagination.

      Comment

      • DU

        #4
        Re: javascript generated html

        quikquic@yahoo. com wrote:
        [color=blue]
        > Suppose I download a html file with javascript in it, for example,
        >
        > <html>
        > <body>
        > <script language="JavaS cript">
        > document.write( "Hello");
        > </script>
        > </body>
        > </html>
        >
        > How can I translate that to pure html,
        >
        > <html>
        > <body>
        > Hello
        > </body>
        > </html>
        >
        > I am looking for a c++ solution.
        >
        > Thanks,
        >
        > qk[/color]

        IMO, your question with your specific example is easy to answer: just
        remove the script tags. But the answer to the general question is it is
        impossible as there are many many ways (DOM methods, even DOM
        attributes) to dynamically add (and/or insert and/or append, modify,
        move, split, etc.. even import) new elements (and/or new text node
        values) into an html file. Adding new DOM nodes with display:none or
        visibility:hidd en or opacity to 0 or etc... (dynamically settable later)
        would still have to be considered as cases to consider.

        Your question is a very valid one though as W3C thinks people are
        resorting to (and/or over-using, mis-using, abusing) DHTML/javascript
        way too often when simple, normal HTML would suffice.

        DU
        --
        Javascript and Browser bugs:

        - Resources, help and tips for Netscape 7.x users and Composer
        - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


        Comment

        • Ivo

          #5
          Re: javascript generated html

          quikquic@yahoo. com (quikquic@yahoo .com) wrote in message news:<ead1f717. 0309181530.13f2 d2da@posting.go ogle.com>...[color=blue]
          > Suppose I download a html file with javascript in it, for example,
          >
          > <html>
          > <body>
          > <script language="JavaS cript">
          > document.write( "Hello");
          > </script>
          > </body>
          > </html>
          >
          > How can I translate that to pure html,
          > I am looking for a c++ solution.
          > Thanks,
          > qk[/color]
          You need a very clever script that interprets the javascript, because
          it has to know in advance what is going to be asked of the javascript.
          Onclicks, onchanges and all other events will have to be assumed. In
          other words, I don't think it 's really possible.

          Why was it written in javascript in the first place??

          If you know that the javascript doesn't change much, but it is still
          too much work to convert all your pages by hand, perhaps you could run
          them as they are, and even add a little javascript that submits the
          generated source back to the server once it has finished generating,
          where you can replace the page with the received html code.
          HTH
          Ivo

          Comment

          • quikquic@yahoo.com

            #6
            Re: javascript generated html

            How does the browser understand javascript? Does the browser transfer
            it into html (if it is something like document.write) first?

            Thanks,


            sandick@mail.co m (Ivo) wrote in message news:<8092d41d. 0309200635.319e c829@posting.go ogle.com>...[color=blue]
            > quikquic@yahoo. com (quikquic@yahoo .com) wrote in message news:<ead1f717. 0309181530.13f2 d2da@posting.go ogle.com>...[color=green]
            > > Suppose I download a html file with javascript in it, for example,
            > >
            > > <html>
            > > <body>
            > > <script language="JavaS cript">
            > > document.write( "Hello");
            > > </script>
            > > </body>
            > > </html>
            > >
            > > How can I translate that to pure html,
            > > I am looking for a c++ solution.
            > > Thanks,
            > > qk[/color]
            > You need a very clever script that interprets the javascript, because
            > it has to know in advance what is going to be asked of the javascript.
            > Onclicks, onchanges and all other events will have to be assumed. In
            > other words, I don't think it 's really possible.
            >
            > Why was it written in javascript in the first place??
            >
            > If you know that the javascript doesn't change much, but it is still
            > too much work to convert all your pages by hand, perhaps you could run
            > them as they are, and even add a little javascript that submits the
            > generated source back to the server once it has finished generating,
            > where you can replace the page with the received html code.
            > HTH
            > Ivo[/color]

            Comment

            • Jerry Coffin

              #7
              Re: javascript generated html

              In article <ead1f717.03092 01535.7948eaed@ posting.google. com>,
              quikquic@yahoo. com says...[color=blue]
              > How does the browser understand javascript? Does the browser transfer
              > it into html (if it is something like document.write) first?[/color]

              No -- the browser has a Javascript interpreter (or invokes a separate
              one) that understands Javascript. HTML has only the VERY most limited
              involvement -- one of the two (usually the browser, I'd guess) has to
              recognize the bit of HTML that marks the end of the Javascript, so
              things switch back to normal HTML mode at the end. What the Javascript
              produces does NOT (in any case of which I'm aware at any rate) get
              converted to HTML to be displayed or anything like that though.

              --
              Later,
              Jerry.

              The universe is a figment of its own imagination.

              Comment

              • Dr John Stockton

                #8
                Re: javascript generated html

                JRS: In article <MPG.19d6aa1299 2193b2989b01@ne ws.clspco.adelp hia.net>,
                seen in news:comp.lang. javascript, Jerry Coffin <jcoffin@taeus. com>
                posted at Sun, 21 Sep 2003 01:15:12 :-[color=blue]
                >In article <ead1f717.03092 01535.7948eaed@ posting.google. com>,
                >quikquic@yahoo .com says...[color=green]
                >> How does the browser understand javascript? Does the browser transfer
                >> it into html (if it is something like document.write) first?[/color]
                >
                >No -- the browser has a Javascript interpreter (or invokes a separate
                >one) that understands Javascript. HTML has only the VERY most limited
                >involvement -- one of the two (usually the browser, I'd guess) has to
                >recognize the bit of HTML that marks the end of the Javascript, so
                >things switch back to normal HTML mode at the end. What the Javascript
                >produces does NOT (in any case of which I'm aware at any rate) get
                >converted to HTML to be displayed or anything like that though.[/color]

                That which is written by document.write, and that which is written by
                DynWrite (FAQ 4.15), is treated as HTML. For example, <br> does not
                make four marks on the page, but causes the insertion point to move to a
                new line.

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
                <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

                Comment

                • quikquic@yahoo.com

                  #9
                  Re: javascript generated html

                  Microsoft's IHtmlDocument(a COM object) can parser html with
                  javascript. For example, if there is
                  var msg1 = "<a href = a.html>link</a>"
                  document.write( msg1)
                  in the file, IHtmlDocument can extract the link, just as a link in
                  html. Thus, IHtmlDocument must have a Javascript interpreter in it,
                  right? I am looking for such a Javascript interpreter which can be put
                  in c++ app.

                  Thanks,

                  qk




                  Dr John Stockton <spam@merlyn.de mon.co.uk> wrote in message news:<xZVgK3CQs gb$Ewbm@merlyn. demon.co.uk>...[color=blue]
                  > JRS: In article <MPG.19d6aa1299 2193b2989b01@ne ws.clspco.adelp hia.net>,
                  > seen in news:comp.lang. javascript, Jerry Coffin <jcoffin@taeus. com>
                  > posted at Sun, 21 Sep 2003 01:15:12 :-[color=green]
                  > >In article <ead1f717.03092 01535.7948eaed@ posting.google. com>,
                  > >quikquic@yahoo .com says...[color=darkred]
                  > >> How does the browser understand javascript? Does the browser transfer
                  > >> it into html (if it is something like document.write) first?[/color]
                  > >
                  > >No -- the browser has a Javascript interpreter (or invokes a separate
                  > >one) that understands Javascript. HTML has only the VERY most limited
                  > >involvement -- one of the two (usually the browser, I'd guess) has to
                  > >recognize the bit of HTML that marks the end of the Javascript, so
                  > >things switch back to normal HTML mode at the end. What the Javascript
                  > >produces does NOT (in any case of which I'm aware at any rate) get
                  > >converted to HTML to be displayed or anything like that though.[/color]
                  >
                  > That which is written by document.write, and that which is written by
                  > DynWrite (FAQ 4.15), is treated as HTML. For example, <br> does not
                  > make four marks on the page, but causes the insertion point to move to a
                  > new line.[/color]

                  Comment

                  • Roland
                    New Member
                    • May 2006
                    • 3

                    #10
                    Hello, you can see generated javascript source with the tracer tool

                    A data processing company providing business information services, company documents and integration through corporate data API's


                    It processes the page as the browser does, and traces every function. Check it. We are developing it and it's still beta, so we appreciate feedback. Thanks

                    Comment

                    Working...