Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I insert the contents of a file into the body of a page on load 2

Status
Not open for further replies.

inta

Technical User
Aug 2, 2001
13
AU
Hello,

I have a text file and an html document that are located in the same directory of my webserver.

I would like to insert the contents of the text file into the body of the html document when the document is loaded.

I have searched for weeks on this and found nothing. The only thing driving me on was seeing this very thing working on a web site of a telco.

Unfortunately the telco no longer has that site running

If you are able to help I would be very grateful.
 
You could try:

Code:
<iframe SRC=&quot;myDoc.txt&quot; FRAMEBORDER=&quot;0&quot;></iframe>
Billy H

bhogar@acxiom.co.uk
 
Yep, very quick answer!
Some example also:
<HTML>
<HEAD>
<TITLE> Load </TITLE>
<script>
function loadFile(){
document.all.txtDiv.innerText = window.frames.txtFrame.document.body.innerText
}
</script>
</HEAD>

<BODY onload=&quot;loadFile();&quot;>
<iframe src=&quot;text.txt&quot; width=&quot;0&quot; height=&quot;0&quot; name=&quot;txtFrame&quot;></iframe>
<div id=&quot;txtDiv&quot; name=&quot;txtDiv&quot;>Text before</div>
</BODY>
</HTML>
 
hi
dianal, note that ur text.txt have 2 have smth like
<body onload=&quot;loadFile()&quot;> if u wanna make it work in dynamic (on some event: button click, image mouseover, etc)
inta, this thread might be interesting for ya:
thread215-115187

regards, vic
 
This is great for IE but how do you achieve the same result in Netscape.

I am looking for a solution that will work with both browsers.
 
This is the code I am using.

The iframe works in IE and the script works in NS
Does anyone know how to get this working on both browsers.
Of note is IE gives me a script error. I would be most grateful for a simple solution to this problem.

for formatting I think that the script method, if it could be made to work with IE would be the best one.

Thank you for your assistance.

<HTML>
<HEAD>
<TITLE> Load Text File</TITLE>
<SCRIPT language = &quot;Javascript&quot;>
var data = new Array();
var i = 0;
var datafile = window.location.href.substring(0,window.location.href.lastIndexOf(&quot;/&quot;) + 1) + &quot;data.txt&quot;;
var url = new java.net.URL(datafile);
var connect = url.openConnection();
var input = new java.io.BufferedReader(new java.io.InputStreamReader(connect.getInputStream()));
var aLine = &quot;&quot;
while((aLine = input.readLine()) != null) {data[i++] = aLine;}
</SCRIPT>
</HEAD>
<BODY>
<table border=&quot;1&quot; height=&quot;100&quot; width=&quot;550&quot;>
<tr>
<td>
<iframe SRC=&quot;./interesting.txt&quot; height=&quot;100&quot; width=&quot;550&quot; FRAMEBORDER=&quot;10&quot;>
<SCRIPT language = &quot;Javascript&quot;>
var temp = &quot;&quot;
for (var j = 0; j < data.length ; j++) temp += data[j] + &quot;<br>&quot;;
document.write(temp);
</SCRIPT>
</iframe>
</td>
</tr>
</table>
</BODY>
</HTML>

In order to see this work, you need two text files located in the same directory as the html page. the text files are called data.txt and interesting.txt The content of the files may be anything you please.
 
What's wrong with using a server-side include to do that?
Code:
<!--#include virtual=&quot;pagename.ext&quot; -->
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top