open file at URL with javascript

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

    open file at URL with javascript

    Hello
    I would like to include text from an external file in my html file. This is
    normally done with <object> or <iframe> but in this case the style sheet and
    internal links (like <a href="#position onpage">) do not work. So I thought
    of writing a little script which does the following

    - open the file http://something.com/textfile.htm
    - put the content of that file in variable "var"
    - document.write( var)

    Is this possible? (also without using activeX objects)

    Thanks Phil


  • Thomas 'PointedEars' Lahn

    #2
    Re: open file at URL with javascript

    Philipp wrote:[color=blue]
    > I would like to include text from an external file in my html file. This is
    > normally done with <object> or <iframe> but in this case the style sheet and
    > internal links (like <a href="#position onpage">) do not work.[/color]

    Would you please describe why it is necessary to access that file
    directly instead of referring to it? And more important, who are
    the authors of that file and do you have their consent to use
    that information in your site?
    [color=blue]
    > So I thought of writing a little script which does the following
    >
    > - open the file http://something.com/textfile.htm[/color]

    Client-side JavaScript has neither native means to open a file
    [color=blue]
    > - put the content of that file in variable "var"[/color]

    nor to read a file
    [color=blue]
    > - document.write( var)[/color]

    so it is simply not possible this way.
    [color=blue]
    > Is this possible? (also without using activeX objects)[/color]

    Unless you are not violating the Same Origin Policy, and the DOM of the
    UA provides the required means, you can manipulate documents displayed
    in container elements.


    PointedEars

    Comment

    • Erwin Moller

      #3
      Re: open file at URL with javascript

      Philipp wrote:
      [color=blue]
      > Hello
      > I would like to include text from an external file in my html file. This
      > is normally done with <object> or <iframe> but in this case the style
      > sheet and internal links (like <a href="#position onpage">) do not work. So
      > I thought of writing a little script which does the following
      >
      > - open the file http://something.com/textfile.htm
      > - put the content of that file in variable "var"
      > - document.write( var)
      >
      > Is this possible? (also without using activeX objects)
      >
      > Thanks Phil[/color]

      Hi Phil,

      No, it is not possible with Javascript alone.
      Javascript is pretty much limitted to the webbrowser and other
      webbrowserwindo ws.

      If you need access to an external file, you need some (very simple)
      serversidehelp.
      In most languages, like PHP, it is extremely simple to do this.

      Good luck,
      Erwin Moller

      Comment

      • Philipp

        #4
        Re: open file at URL with javascript


        "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> a écrit dans le message de
        news:3FC222DE.9 020103@PointedE ars.de...[color=blue]
        > Philipp wrote:[color=green]
        > > I would like to include text from an external file in my html file. This[/color][/color]
        is[color=blue][color=green]
        > > normally done with <object> or <iframe> but in this case the style sheet[/color][/color]
        and[color=blue][color=green]
        > > internal links (like <a href="#position onpage">) do not work.[/color]
        >
        > Would you please describe why it is necessary to access that file
        > directly instead of referring to it? And more important, who are
        > the authors of that file and do you have their consent to use
        > that information in your site?[/color]

        :-)) (I prefer taking that kind of remark with a smile).
        Actually imagine you have the same footer for all your webpages, well you
        wouldn't want to rewrite and update the same part in all your files if you
        could just include a file with just the footer which would then be the only
        file to be updated.
        [color=blue][color=green]
        > > - open the file http://something.com/textfile.htm[/color]
        >
        > Client-side JavaScript has neither native means to open a file[/color]

        Ok that's the info I needed.
        Thanks to all for answers Phil


        Comment

        • Fabian

          #5
          Re: open file at URL with javascript

          Philipp hu kiteb:
          [color=blue]
          > "Thomas 'PointedEars' Lahn" <PointedEars@we b.de> a $BqD(Brit dans le
          > message de news:3FC222DE.9 020103@PointedE ars.de...[color=green]
          >> Philipp wrote:[color=darkred]
          >>> I would like to include text from an external file in my html file.
          >>> This is normally done with <object> or <iframe> but in this case
          >>> the style sheet and internal links (like <a
          >>> href="#position onpage">) do not work.[/color]
          >>
          >> Would you please describe why it is necessary to access that file
          >> directly instead of referring to it? And more important, who are
          >> the authors of that file and do you have their consent to use
          >> that information in your site?[/color]
          >
          > :-)) (I prefer taking that kind of remark with a smile).
          > Actually imagine you have the same footer for all your webpages, well
          > you wouldn't want to rewrite and update the same part in all your
          > files if you could just include a file with just the footer which
          > would then be the only file to be updated.
          >[color=green][color=darkred]
          >>> - open the file http://something.com/textfile.htm[/color]
          >>
          >> Client-side JavaScript has neither native means to open a file[/color]
          >
          > Ok that's the info I needed.
          > Thanks to all for answers Phil[/color]

          Dont give up on client side yet.

          Suppose you have every page linking to an external javascript file. That
          file can contain a function called writefooter(), which contains a bunch
          of document.write statements. By calling this function in teh
          appropriate palce on each page, you have the functional equivalent.

          However, this remains a sub-optimal solution due to the inherent
          problems with client side applications.


          --
          --
          Fabian
          Visit my website often and for long periods!


          Comment

          Working...