faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

117 of 490 people (24%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

How to Read a text file using javascript

Apr 7th, 2008 23:17
ha mo, Colin Fraser, sushil Pan,


The issue is where is the file you want to read? If it is on the user's
computer, then no, it cannot currently be done using Javascript. (Java
or PHP are different)
If you have the file to be read on your site then you can just put a
simple HTML link to it, browsers do read text files. 
If you have several text files for users to select one from then you can
either use simple links as suggested above or you can use a simple
window.open() function. I would suggest that you use a variable name
here eg.:
function winOpen(fname) {   
window.open(""+fname+"","toolbar=no,status=no,menubar=no,scrollbars=yes,
      left=50,top=100,width=250,height=400") 
}    
In the web page you can use a form with buttons or images or simple text
as the visual cue and include the event handler:
     onClick="winOpen('text1.txt')"
changing the name of the file to suit what you need. You can repeat this
call to the function any number of times. 
This is the simplest way to answer your question.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com