View Full Version : Read from external .txt file
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
What if .txt file contains only data? Like this:
wib.txt
code
Hello world
How to code html then?
You could try innerText or innerHTML method
<html>
<script src="wib.txt"></script>
<script>
oDiv.innerText=message
</script>
</html>
<div id="oDIV"></div>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.