View Full Version : loading text documents
kwhubby
02-21-2003, 02:40 AM
hi, how would i load a text document to a variable?
joeframbach
02-21-2003, 03:23 AM
im afraid javascript cant do that with *.txt files, but a good alternative would be *.js files.
example:
variables.js:
--------------------------
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>
<script...>
alert(name + "\'s favorite site is " + favSite + ", and his favorite language is " + lang + ".")
</script>
--------------------------
*.js files can also incluse functions etc.
kwhubby
02-21-2003, 04:24 AM
shoulnd you be able to get a text document into an iframe, and load the iframe outertext into a variable :)
TheMenace
02-21-2003, 09: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.
kwhubby
02-22-2003, 02: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:
brothercake
02-22-2003, 05: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.
kwhubby
02-22-2003, 06: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???...
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.
kwhubby
02-22-2003, 07: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)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.