1

I know few firefox version allow to read file without http or https, Is there any way to read file in jquery or javascript with file:// protocol ? I am developing static application, which works well with web server, if I am able to do something similar to the job of below Jquery.ajax function with protocol being file:// I will be very happy

This works well if I have web server (http/https) what can be done for file:// ?

$.ajax({
        type: "GET",
        url: "http://localhost/something/somefile.txt",
        dataType: "text",
        success: function(data){ dothis(data); }
       });

What I will do if I don't have web server ? I know due to SOP (Same origin policy) modern browsers doesn't allow. Is there any alternate method to do the similar job so that which does support all browser with protocol being file:// ?

user3637224
  • 585
  • 1
  • 3
  • 22

2 Answers2

0

If you just read files, consider setting up a one-click HTTP server on your computer.

For example I use Web Server for Chrome.

yzn-pku
  • 1,082
  • 7
  • 14
0

You may like to use FileSystem API which comes in html5. This has several features which i guess you are looking for. what you can do with this api are:

  1. Requesting a file system
  2. Requesting storage quota
  3. Working with files
  4. Creating a file
  5. Reading a file by name
  6. Writing to a file
  7. Appending data to a file
  8. Duplicating user-selected files
  9. Removing a file
  10. Working with directories
  11. Creating directories
  12. Subdirectories
  13. Reading a directory's contents
  14. Removing a directory
  15. Copying, renaming, and moving
  16. filesystem: URLs

The above points are taken from html5rocks. Other than this you can look at MDN for filesystem api.


Note:

In April 2014, it was announced on public-webapps that the Filesystem API spec is not being considered by other browsers. For now, the API is Chrome-specific and it's unlikely to be implemented by other browsers and is no longer being standardized with the W3C.

Community
  • 1
  • 1
Jai
  • 74,255
  • 12
  • 74
  • 103