0

How do you allow Google Chrome on a Chromebook to access a local file?

For eg: $.get('filename') fails when executing a local file.

I'm getting this error message in my console.

XMLHttpRequest cannot load file:///. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Updated:

I want to develop a website using my Chromebook which will read files stored with in the project. The file that it reads from is stored locally only for testing purposes only.

When the website is hosted online (for eg using github pages), both the code for the website and the data that it reads from will be hosted online(for eg on github). I hope that helps you understand my question.

Ishan
  • 3,931
  • 11
  • 37
  • 59
  • Are you developing a Chrome App? Or a regular web site? It would help to understand the context in which your JavaScript code is running. Also, see [this similar question](http://stackoverflow.com/q/4819060/426790). – Greg Sadetsky Jul 15 '16 at 02:58
  • I'm developing a chrome extension as well as a regular website? Would like to see a solution for both. – Ishan Jul 15 '16 at 04:34
  • A regular website cannot read local files through XHR, be it on a Chromebook or otherwise. This is a basic security mechanism that browsers implement (if it weren't the case, any web site could read any file on your computer). Chrome Extensions don't have more privileges in that regard. Chrome Apps, though, do have access to a fileSystem API. See [here](https://developer.chrome.com/apps/app_storage#filesystem) and [here](https://developer.chrome.com/apps/fileSystem) for docs on that. – Greg Sadetsky Jul 15 '16 at 05:06
  • But, then how do I read data from a local file on a chromebook when making a website? – Ishan Jul 15 '16 at 22:51
  • I'm not sure that I understand. Do you want to develop a website using your Chromebook and store the files there, and then access them from your site? Or do you want to create a website (hosted somewhere online) that is able to read local files from the Chromebook? – Greg Sadetsky Jul 16 '16 at 16:31
  • @GregSadetsky. See my updated question. – Ishan Jul 17 '16 at 00:55
  • I think that I understand now. I would suggest googling "web development chromebook", there are a lot of different ways to ago about it (see [here](http://www.eq8.eu/blogs/18-chromebook-for-web-developers) and [here](https://divshot.com/blog/tips/using-a-chromebook-for-web-development/)). Many people use online services to develop their sites; you also have the option of installing another operating system on your Chromebook -- see [here](https://medium.com/@martinmalinda/ultimate-guide-for-web-development-on-chromebook-part-1-crouton-2ec2e6bb2a2d#.joeecatxv) for details. – Greg Sadetsky Jul 17 '16 at 13:16

0 Answers0