Read HTML-code from file

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

    Read HTML-code from file

    Hi,

    I want to write a script that (run from a file on the local HD) reads
    another local html-file into a variable, then make some changes to it, and
    then output the result in a way that makes it simple for the user to save
    it again. And all of this should run in any current browser, not just IE.

    I managed to access the code of the current document by
    code = document.docume ntElement.inner HTML

    But when I open another window with the file I want to edit, all I get is
    <head></head><body></body>

    For the output I tried to do document.write in an output window, but I
    can't save the code I generate there, all I get is the sourcecode of my
    script page (the opener of the page I try to save). Any hints?

    Oh, just in case that matters, I'm using Galeon on Linux.

    I hope someone out there can help me.

    Thanks, Christian
  • Fabian

    #2
    Re: Read HTML-code from file

    Christian Schmitt hu kiteb:

    [color=blue]
    > For the output I tried to do document.write in an output window, but I
    > can't save the code I generate there, all I get is the sourcecode of
    > my script page (the opener of the page I try to save). Any hints?[/color]

    Yep. Use a programing language in an environment that actuially has
    permission to write a file. This does not apply to javascript running in
    teh context of a web browser.


    --
    --
    Fabian
    Visit my website often and for long periods!
    AGAM69 menghadirkan inspirasi desain kreatif, solusi digital, pengembangan teknologi, serta inovasi modern untuk kebutuhan bisnis dan profesional.


    Comment

    • Martin Honnen

      #3
      Re: Read HTML-code from file



      Christian Schmitt wrote:[color=blue]
      > I want to write a script that (run from a file on the local HD) reads
      > another local html-file into a variable, then make some changes to it, and
      > then output the result in a way that makes it simple for the user to save
      > it again. And all of this should run in any current browser, not just IE.
      >
      > I managed to access the code of the current document by
      > code = document.docume ntElement.inner HTML
      >
      > But when I open another window with the file I want to edit, all I get is
      > <head></head><body></body>
      >
      > For the output I tried to do document.write in an output window, but I
      > can't save the code I generate there, all I get is the sourcecode of my
      > script page (the opener of the page I try to save). Any hints?
      >
      > Oh, just in case that matters, I'm using Galeon on Linux.[/color]

      This sounds all like a task for server side scripting with PHP or JSP or
      ASP.
      But I think Galeon is Mozilla based so maybe it offers
      XMLHttpRequest
      e.g.
      if (typeof XMLHttpRequest != 'undefined') {
      var httpRequest = new XMLHttpRequest( );
      httpRequest.ope n('GET', 'whatever.html' , false);
      httpRequest.sen d(null);
      alert(httpReque st.responseText );
      }
      That way you can read text pages from the same server the page with the
      script is loaded from.


      --

      Martin Honnen


      Comment

      • Christian Schmitt

        #4
        Re: Read HTML-code from file



        On Fri, 21 Nov 2003, Fabian wrote:
        [color=blue]
        > Christian Schmitt hu kiteb:
        >
        >[color=green]
        > > For the output I tried to do document.write in an output window, but I
        > > can't save the code I generate there, all I get is the sourcecode of
        > > my script page (the opener of the page I try to save). Any hints?[/color]
        >
        > Yep. Use a programing language in an environment that actuially has
        > permission to write a file. This does not apply to javascript running in
        > teh context of a web browser.
        >[/color]

        Well, for several reasons I'm limited to Javascript. And I don't want to
        initiate the saving from the script, just create a document that the user
        can save manually.

        PL

        Comment

        • Christian Schmitt

          #5
          Re: Read HTML-code from file



          On Fri, 21 Nov 2003, Martin Honnen wrote:
          [color=blue]
          >
          >
          > Christian Schmitt wrote:[color=green]
          > > I want to write a script that (run from a file on the local HD) reads
          > > another local html-file into a variable, then make some changes to it, and
          > > then output the result in a way that makes it simple for the user to save
          > > it again. And all of this should run in any current browser, not just IE.
          > >
          > > I managed to access the code of the current document by
          > > code = document.docume ntElement.inner HTML
          > >
          > > But when I open another window with the file I want to edit, all I get is
          > > <head></head><body></body>
          > >
          > > For the output I tried to do document.write in an output window, but I
          > > can't save the code I generate there, all I get is the sourcecode of my
          > > script page (the opener of the page I try to save). Any hints?
          > >
          > > Oh, just in case that matters, I'm using Galeon on Linux.[/color]
          >
          > This sounds all like a task for server side scripting with PHP or JSP or
          > ASP.[/color]

          This all takes place locally, the script is not on a server.
          [color=blue]
          > But I think Galeon is Mozilla based so maybe it offers
          > XMLHttpRequest
          > e.g.
          > if (typeof XMLHttpRequest != 'undefined') {
          > var httpRequest = new XMLHttpRequest( );
          > httpRequest.ope n('GET', 'whatever.html' , false);
          > httpRequest.sen d(null);
          > alert(httpReque st.responseText );
          > }
          > That way you can read text pages from the same server the page with the
          > script is loaded from.
          >[/color]
          XMLHttpRequest seems to be supported, but hangs the browser :-((
          Perhaps because I try to read a local file?
          Any other ideas?

          PL

          Comment

          • Martin Honnen

            #6
            Re: Read HTML-code from file



            Christian Schmitt wrote:[color=blue]
            > On Fri, 21 Nov 2003, Martin Honnen wrote:[color=green]
            >>Christian Schmitt wrote:
            >>[color=darkred]
            >>>I want to write a script that (run from a file on the local HD) reads
            >>>another local html-file into a variable, then make some changes to it, and
            >>>then output the result in a way that makes it simple for the user to save
            >>>it again. And all of this should run in any current browser, not just IE.
            >>>
            >>>I managed to access the code of the current document by
            >>>code = document.docume ntElement.inner HTML
            >>>
            >>>But when I open another window with the file I want to edit, all I get is
            >>><head></head><body></body>
            >>>
            >>>For the output I tried to do document.write in an output window, but I
            >>>can't save the code I generate there, all I get is the sourcecode of my
            >>>script page (the opener of the page I try to save). Any hints?
            >>>
            >>>Oh, just in case that matters, I'm using Galeon on Linux.[/color]
            >>
            >>This sounds all like a task for server side scripting with PHP or JSP or
            >> ASP.[/color]
            >
            >
            > This all takes place locally, the script is not on a server.[/color]

            I understand that you are attempting things locally, but it sounds more
            like a task to be solved with PHP or ASP or JSP as there you don't run
            into the restrictions client side JavaScript has to access the file
            system or any Web server.
            [color=blue][color=green]
            >>But I think Galeon is Mozilla based so maybe it offers
            >> XMLHttpRequest
            >>e.g.
            >> if (typeof XMLHttpRequest != 'undefined') {
            >> var httpRequest = new XMLHttpRequest( );
            >> httpRequest.ope n('GET', 'whatever.html' , false);
            >> httpRequest.sen d(null);
            >> alert(httpReque st.responseText );
            >> }
            >>That way you can read text pages from the same server the page with the
            >>script is loaded from.
            >>[/color]
            >
            > XMLHttpRequest seems to be supported, but hangs the browser :-((
            > Perhaps because I try to read a local file?[/color]

            The third argument to the open() call is the asynchronous mode, in the
            example above that is false meaning the send() call later will block the
            beowser till the file is loaded.
            You can also perform asynchronous requests, then you need to set up an
            httpRequest.onr eadystate
            handler.

            If you do not even want to read files via http but only from the local
            file system then perhaps XPConnect can do that with Galeon


            --

            Martin Honnen


            Comment

            • Christian Schmitt

              #7
              Re: Read HTML-code from file



              On Fri, 21 Nov 2003, Martin Honnen wrote:
              [color=blue][color=green][color=darkred]
              > >>But I think Galeon is Mozilla based so maybe it offers
              > >> XMLHttpRequest
              > >>e.g.
              > >> if (typeof XMLHttpRequest != 'undefined') {
              > >> var httpRequest = new XMLHttpRequest( );
              > >> httpRequest.ope n('GET', 'whatever.html' , false);
              > >> httpRequest.sen d(null);
              > >> alert(httpReque st.responseText );
              > >> }
              > >>That way you can read text pages from the same server the page with the
              > >>script is loaded from.
              > >>[/color]
              > >
              > > XMLHttpRequest seems to be supported, but hangs the browser :-((
              > > Perhaps because I try to read a local file?[/color]
              >
              > The third argument to the open() call is the asynchronous mode, in the
              > example above that is false meaning the send() call later will block the
              > beowser till the file is loaded.[/color]

              That much I found out already, but why doesn't it load at all? Loading a
              small local file should happen instantly.
              [color=blue]
              > You can also perform asynchronous requests, then you need to set up an
              > httpRequest.onr eadystate
              > handler.
              >
              > If you do not even want to read files via http but only from the local
              > file system then perhaps XPConnect can do that with Galeon
              > http://www.faqts.com/knowledge_base/...d/23360/fid/53
              >[/color]

              But this works only in Mozilla-based browsers, right? I need something
              that works in ALL (well, most of the common ones, at least) current
              browsers on all platforms.

              Christian

              Comment

              • VK

                #8
                Re: Read HTML-code from file

                > But this works only in Mozilla-based browsers, right? I need something[color=blue]
                > that works in ALL (well, most of the common ones, at least) current
                > browsers on all platforms.[/color]

                Platform independent bugs-free 99% reliable local File I/O interface? If
                anyone gets a solution of this, don't post it here, but sell to Sun Java
                for a good money. They are poking on the roses with it for a decade now,
                and it's still buggy like hell. Too many issues are involved here, and
                it would take a dozen of pages just to explain them (besides technical,
                a lot of security related).

                You have an easy solution with Windows systems with IE installed. Its
                implementation of JavaScript (JScript) supports ActiveXObject, which
                works just fine with local files. That would cover about 85% of the
                potential customers.

                The only totally universal solution would be to make a JavaScript editor
                and provide an event-driven browser-dependent prompt like "Choose File >
                Open to open the file you want to edit" and "Choose File > Save As to
                save the changes you've made".


                Comment

                Working...