2

On my website I got a form with an input:

<input type="file" id="text">

I'd like to get a content of a text file into a string variable using JavaScript. I used File API, but obviously it's not working in IE or some older browsers. I tried to use new ActiveXObject("Scripting.FileSystemObject") but some security reasons won't let me use it in IE, as it gives me an error: "Automation Server can't create object". From what I read, it seems to me that this cannot be used then without changing some security options in a browser and that's not what I want my users to do.

So is there any other simple way to read a file's content by using JavaScript only and to make it work in older browsers?

3
  • I don't think so. You can try uploading the file to a server and then reading it back from the server using AJAX. Commented Sep 4, 2012 at 7:51
  • Well, uploading the file is a thing I wanted to resign from, but thanks Commented Sep 4, 2012 at 7:58
  • @TedHopp you cannot upload file via ajax Commented Apr 14, 2013 at 12:37

1 Answer 1

1

Most older browsers, no. There are some strict security limitations for Javascript.

If you are focusing IE/Windows-only and are trying to write something for your own local use, then HTA files have access to read-write routines.

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

1 Comment

Thank you for a reply but sadly HTA files aren't satisfying for me.

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.