PDA

View Full Version : Read from external .txt file


Kyle
10-05-2002, 09:22 AM
Is there a way to read the content of an external .txt file, and assign it to a var?

martin_narg
10-05-2002, 11:37 AM
You can use any plain ASCII file so long as the content is correctly syntaxed javascript.

for example:
wib.txt:

var message = "hello world";


myPage.html:

<html>
<script src="wib.txt"></script>
<script>
alert( message );
</script>
</html>


hope this helps,

m_n

Kyle
10-05-2002, 04:39 PM
What if .txt file contains only data? Like this:

wib.txt

code

Hello world



How to code html then?

Mr J
10-05-2002, 07:50 PM
You could try innerText or innerHTML method


<html>
<script src="wib.txt"></script>
<script>
oDiv.innerText=message
</script>
</html>




<div id="oDIV"></div>