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?
you can only use this code on local files selected via <input type=file>.
it will NOT work for URLs.
try using the free YQL webservice to convert the page to JSON-packed base64, and unpack the data on the client.
this solution needs window.atob(), which comes with at least chrome and ff.
for other browsers, download a base64 DECODE routine, and name the function "atob". that should make it work everywhere.
Code:
window.nwsCB=function(data){
var fileContent=(atob(data.query.results.url.split(",")[1]));
alert( fileContent );
}
function addScript(u){ var sc2=document.createElement('script'); sc2.src=u; document.getElementsByTagName('*')[1].appendChild(sc2) }
addScript("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20data.uri%20where%20url%3D%22http%3A%2F%2Fwww.swpc.noaa.gov%2Fftpdir%2Findices%2Fevents%2Fevents.txt%22&format=json&diagnostics=true&callback=nwsCB");
see the YQL console for making new URLs to use with addScript if you want to grab other pages.
Hi,
i tried ur example code and it worked.. i need some modification in dat..rite nw u r giving the user to browse for a file and based on the selected file the operation is performed.. but i want my script to always read from the same file..der is no option to browse for the file.when the page loads this function shud be called automatically and the hardcoded file shud be read. can u help me out with this please..
Thanks,
Hi,
i want my script to always read from the same file..der is no option to browse for the file.when the page loads this function shud be called automatically and the hardcoded file shud be read
that is not allowed by any browser.
if you have the file on your server, next to an html file, then you can use simple ajax to grab the file's contents. search for a basic ajax demo for that code.
Thanks for the reply.. actually i have urgent req for it.. i will tell u the full scenrio..if der is another way plz tell me dat..
i am using unix server.my html script is located in /var/www/etc/html path and the file containing the names is also stored in the same place.. i want to read this file n store all the names in an dropdown combo box in my html page.. i got a code which reads frm an array and stores in dropdown box..i mixed dat code with ur code which reads each line frm the file n stores in the array..bt i need that the same file is read everytime wich contains the name wich has to be displayed in combo box..
If u have any code plz send me..i need it urgently..
in brief
1) read content of the file
2) store the content into array
3) read the array n store the content into combobox in html.
Bookmarks