View Full Version : loading text documents

02-21-2003, 03:40 AM
hi, how would i load a text document to a variable?

02-21-2003, 04:23 AM
im afraid javascript cant do that with *.txt files, but a good alternative would be *.js files.


var name="Joe Frambach"
var favSite="http://www.codingforums.com"
var lang="Javascript"

the head of your html page:
<script language='javascript' src='variables.js'></script>
alert(name + "\'s favorite site is " + favSite + ", and his favorite language is " + lang + ".")

*.js files can also incluse functions etc.

02-21-2003, 05:24 AM
shoulnd you be able to get a text document into an iframe, and load the iframe outertext into a variable :)

02-21-2003, 10:52 AM
The easiest way to do it would be use Server Side Includes. Have a look at Big Nose Bird (http://www.bignosebird.com) the articles there have lots of SSI info.

02-22-2003, 03:21 AM
I was able to get it to work
with a hidden div tag, with an iframe to the source of a text document, than difine a variable to getElementsByTagName('HTML')[0].innerText
of the iframe name, and wa la, I get the text of a text document into a variable using html/javascript

:D :D
:cool: :cool:

02-22-2003, 06:22 AM
I wouldn't rely on that personally - afaik only ie5.5, ie6 and mozilla will let you do that; moz also splits the text into nodes every x bytes (can't remember what x is), whereas in IE it's all in childNodes[1]

But really... you shouldn't rely on a text document having a DOM at all. The best way to import client-side data into javascript is to keep the data in XML.

02-22-2003, 07:55 AM
I don;t really care at all about netscape or opera or anything else besides ie 5-6

does ie split the data up too???...

02-22-2003, 07:57 AM
Originally posted by kwhubby
I don;t really care at all about netscape or opera or anything else besides ie 5-6

That's a shame.

And no, IE does not split the data up. It keeps it all in one TextNode.

02-22-2003, 08:07 AM
this is for main use on my computer, not really for wide sharing with the few netscape users out there (greatly increasing because of aol swapping to moz)