1

I have a text file i want to read in my html page,both are in the same directory and i am not running a server. I intend that my users use the script offline(basically text manipulation based on expressions and preserving new line characters) .

  1. I tried ajax call but mostly cross domain origin problem occured and i know most of the users will have this security tighened up in many browsers , so its not of use to circumvent this in only in my browser.

  2. I want to support many browsers including old browsers as in IE7,8 etc which do not support HTML5 filereader.for the same reason reading using filesystemobject or activex is not good.

  3. Reading the file after user select it as input , is this possible?Otherwise i would have no option then using other technologies like php,java etc which may expect my user to setup these.

Please excuse me if i am repeating this but i am a beginner web developer. I know that reading local files via javascript is not possible but is there any other way?

5
  • 1
    vb script supports client side file reading and only ie .. javascript does not support file handling Commented Jan 22, 2014 at 11:44
  • only server side and php does Commented Jan 22, 2014 at 11:45
  • ok and no tricks around it if the user upload the file or do some configuration? i mean the last thing is copying and pasting text file content into a text box. Commented Jan 22, 2014 at 11:46
  • you find your way here mate, grz, NOW give some code so it can be overlooked/looked Commented Jan 22, 2014 at 11:48
  • thanks for the comment mate, i listed the above option that i have tried.most of them require user to configure his browser security if you are doing it offline.There is no problem with the code, lot of examples available online. Commented Jan 22, 2014 at 11:52

1 Answer 1

1

If you can't support FileReader, then the answer is pretty much no (at least, if you want to support a large range of browsers rather than rely on convenient feature x of browser y). Unless : you indeed increase the requirements for running the application and get some sort of local server going (for instance node.js, Apache, TomCat, etc. but like you said this will greatly increase the requirements and become cumbersome for users).

You could also rethink what it is you're trying to achieve. What are the contents of the file you want to read ? Can't these contents be part of the HTML file you're serving to your users (i.e. a large JSON Object inside a script-tag ?)

On possibility of using node.js:

Node.js is quite easy to install and assuming you are requiring from your users to install it, you can use it as a local server, which is a nodejs script of about two lines in size :). Running it locally would also omit the need to upload anything anywhere as you can directly read from the file system using the fs-object (see sitepoint.com/accessing-the-file-system-in-node-js).

STILL: from both a design and ease-of-use-point of view you might want to resort to using either another technology, or include the text file content inside the HMTL file

Sign up to request clarification or add additional context in comments.

4 Comments

yep ,that would be the last option, i want to manipulate text from a file, a simple solution i have is to let them copy and paste it in a text box
i am less experience about node js but if i create a simple server using node js and allow user to upload his text file to it and then use it from there. is this possible?does it need admin rights or user configuration?well initially it seems to run a server it also need node program.
Node.js is quite easy to install and assuming you are requiring from your users to install it, you can use it as a local server, which is a nodejs script of about two lines in size :). Running it locally would also omit the need to upload anything anywhere as you can directly read from the file system using the fs-object (see sitepoint.com/accessing-the-file-system-in-node-js). STILL: from both a design and ease-of-use-point of view you might want to resort to using either another technology, or include the text file content inside the HMTL file...
you are right for ease of use and maintainability it is better to look for technology with such native support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.