By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,517 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,517 IT Pros & Developers. It's quick & easy.

open file at URL with javascript

P: n/a
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="#positiononpage">) 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
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Philipp wrote:
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="#positiononpage">) do not work.
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?
So I thought of writing a little script which does the following

- open the file http://something.com/textfile.htm
Client-side JavaScript has neither native means to open a file
- put the content of that file in variable "var"
nor to read a file
- document.write(var)
so it is simply not possible this way.
Is this possible? (also without using activeX objects)


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
Jul 20 '05 #2

P: n/a
Philipp wrote:
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="#positiononpage">) 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


Hi Phil,

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

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
Jul 20 '05 #3

P: n/a

"Thomas 'PointedEars' Lahn" <Po*********@web.de> a écrit dans le message de
news:3F**************@PointedEars.de...
Philipp wrote:
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="#positiononpage">) do not work.


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?


:-)) (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.
- open the file http://something.com/textfile.htm


Client-side JavaScript has neither native means to open a file


Ok that's the info I needed.
Thanks to all for answers Phil
Jul 20 '05 #4

P: n/a
Philipp hu kiteb:
"Thomas 'PointedEars' Lahn" <Po*********@web.de> a $BqD(Brit dans le
message de news:3F**************@PointedEars.de...
Philipp wrote:
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="#positiononpage">) do not work.


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?


:-)) (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.
- open the file http://something.com/textfile.htm


Client-side JavaScript has neither native means to open a file


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


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!
http://www.lajzar.co.uk

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.