how to use javascript in html to read txt file and display it ?
I am newer ,pls help me achieve the following functions,
1>use javascript in html to read local txt file (when client browser open this html,start to read local txt file)
2>find all these lines including "@" from the txt file.
3>display the lines including "@" in client browser(when he open this html)
that'all,I think it is easy to do it,but i don't know,looking forwards to your help(best to give me entire codes,very appreciate ),thanks very much.
I am newer ,pls help me achieve the following functions,
1>use javascript in html to read local txt file (when client browser open this html,start to read local txt file)
2>find all these lines including "@" from the txt file.
3>display the lines including "@" in client browser(when he open this html)
that'all,I think it is easy to do it,but i don't know,looking forwards to your help(best to give me entire codes,very appreciate ),thanks very much.
The forum is not a coding service. You need to show your attempts and we can comment on them.
Read the 'stickies' at the main site about homework assignments.
Note, JS cannot read a text file on a local computer (with the exception on only one browser)
The most common access to a text file is from an internet server using ajax code logic.
i can't get answer ,can u give me suggestion how to replace fopen and fread using js same command? acutally i have a confuse,because in this link : http://www.ehow.com/how_5996745_read...avascript.html ,it said it is js command.
looking forwards to your help,thanks.
i can't get answer ,can u give me suggestion how to replace fopen and fread using js same command? acutally i have a confuse,because in this link : http://www.ehow.com/how_5996745_read...avascript.html ,it said it is js command.
looking forwards to your help,thanks.
Probably because it only works on MSIE.
What browser and version are you using?
don't listen to people who don't know how to do things...
Code:
<!DOCTYPE html>
<html>
<head>
<title>reading file</title>
<script type="text/javascript">
var reader = new FileReader();
function readText(that){
if(that.files && that.files[0]){
var reader = new FileReader();
reader.onload = function (e) {
var output=e.target.result;
//process text to show only lines with "@":
output=output.split("\n").filter(/./.test, /\@/).join("\n");
document.getElementById('main').innerHTML= output;
};//end onload()
reader.readAsText(that.files[0]);
}//end if html5 filelist support
}
</script>
</head>
<body>
<input type="file" onchange='readText(this)' />
<div id="main"></div>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript">
var nesne ;
if(navigator.appName.search('Microsoft')>-1) { nesne = new ActiveXObject('MSXML2.XMLHTTP'); }
else { nesne = new XMLHttpRequest(); }
function yolla() {
nesne.open('get', 'bilgi.txt', true);
nesne.onreadystatechange= cevap;
nesne.send(null);
}
function cevap() {
if(nesne.readyState==4) {
var el = document.getElementById('bilgi');
el.innerHTML = nesne.responseText;
}
}
</script>
</head>
<body>
<input type="button" value="bilgi.txt dosyadaki yazıyı buraya al" onclick="yolla()">
<div id="bilgi"></div>
</body>
</html>
bilgi.txt
Code:
5
I use firefox 4.0b9
I clicked button, it is writing 5 in div
The Time Through Ages
In the Name of Allah, Most Gracious, Most Merciful
1. By the Time,
2. Verily Man is in loss,
3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy.
If all the writers had the honesty to say that they use HTLML5 and that their scripts work only on the most recent browsers, we avoid many confusions... The HTML5 proposed solution work only with windows7 (Internet explorer 9 can not be settled on older system).
A solution supported by more browsers an system consists, as suggests Ayse, in using Ajax. Here is an other example (See the source) build with the page XHTMLRequest functions from Peter-Paul Koch...
I am using the code that 'rnd me' submitted, but am having issues hard inputting the address into it. I'm building a situational awareness page at work that runs off of our local drive. Currently we just iframe a few .txt files from the Space Weather Prediction Center, but I would like to readastext them and write them so I could modify the text with css. I do not need to use the input=file as the address never changes, but I'm having a heck of time getting to work... any thoughts?
Code:
<html>
<head>
<title>SWPC Events</title>
<script type="text/javascript">
var reader = new FileReader();
function readText(){
var reader = new FileReader();
reader.onload = function (e) {
var output=e.target.result;
document.getElementById('main').innerHTML= output;
}
reader.readAsText('http://www.swpc.noaa.gov/ftpdir/indices/events/events.txt');
}
</script>
</head>
<body>
<input type="button" id="decode" onclick="readText()" value="Decode">
<div id="main"></div>
</body>
</html>
If all the writers had the honesty to say that they use HTLML5 and that their scripts work only on the most recent browsers, we avoid many confusions... The HTML5 proposed solution work only with windows7 (Internet explorer 9 can not be settled on older system).
not true.
firefox and chrome run on windows XP-win8 and mac and mobile.
IE9 only needs windows Vista, not win7.
all told, HTML is supported on about 9/10 devices, and that final ten percent should be converted over the next couple of years to about 2%.
Bookmarks