1

Is there any way to enable native JavaScript to read local file on the disk?

no Ajax, no JQuery or other JavaScript library, only use the native JavaScript?

I have searched, but it seems there is no way to do this.

My requirements are that when the Internet can not be accessed, I will show a warning page in the Chrome browser.

1
  • what about HTML5 Filereader API? Commented Aug 7, 2014 at 7:20

3 Answers 3

1

HTML5, have a File Api, if you are interested in reading file, just for the reading - MSDN, HTML5rocks.

If you are more interested in the case when the user is offline, and your application needs a storage, you can take a look at localstorage - MDN, diveintohtml5. There is an example how to check if it is available, although CanIUse says it is currently available everywhere. Here is a live example.

Hope this will help, in your case which seems to be the synchronization after being offline.

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

Comments

1

If you are using JavaScript in a browser, there is no way to access an arbitrary file from the local filesystem like this. XMLHTTPRequest can be used to access files natively without a library like jQuery, but it prevents access to local files as a security measure.

However, you can use a cache.manifest file to set up an offline version of an HTML 5 site/app.

1 Comment

Thank you I will have a look.
1

You can use a combination of <input type="file"/> and Javascript's window.FileReader to read file. It has many methods of receiving the data, easiest being FileReader.readAsBinaryString(file); You can only read files that a user has selected from a file browser.

Here's Mozilla Developer Network's documentation on it.

For your uses, however, it seems like developing a Chrome extension would be a better solution to manipulating the way Google Chrome works.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.