At the moment, due to the chromium security policy , it is not possible to load local files via ajax without the “--allow-file-access-from-files” argument. But I currently need to create a web application where the database is an xml file (at least json), located next to index.html. It is understood that the user can run this application locally. Are there any workarounds for cross-browser (ie11 +) reading the xml- (json-) file, without wrapping it into a function and renaming it to js format?


UPD

There is code for IE, but with it, as it turned out, there were no problems and there was no

function loadXMLFile(filename) { return new Promise(function(resolve, reject) { // Если мы имеем дело с IE, то работает с ActiveX-контентом if('ActiveXObject' in window) { // Получение xml-текста из файла для осла var xmlDoc = new ActiveXObject('Microsoft.XMLDOM'); xmlDoc.async = false; xmlDoc.load(filename); resolve(xmlDoc.xml); } else { // Если мы работаем с нормальными браузерами, // то здесь необходимо как-то получить xml-файл // ... // } } } 
  • one
    That is, locally, there will not be a web server? - heff
  • @heff No, of course, otherwise there would be no problem - Vasya Shmarovoz
  • Comments are not intended for extended discussion; conversation moved to chat . - PashaPash

1 answer 1

The following options are possible:

  1. Browser extension. It works almost like local files (in the sense that the files are static and lie in the file system) - but for access to resources, it’s not the file:///path/to/file scheme, but the chrome-extension:///{guid}/path/to/file scheme chrome-extension:///{guid}/path/to/file . In this scheme, there are no restrictions on access to the resources of your application. All you need is to create the right manifest and package the application into the archive. Well, and add it to the browser, of course.

    Here is the full format of the manifest file: https://developer.chrome.com/extensions/manifest

    The minimum manifest is this:

     { "manifest_version": 2, "name": "Мое приложение", "version": "1.0", "default_locale": "ru", "description": "Описание приложения", "icons": { "16": "icon16.png", "48": "icon48.png", "128": "icon128.png" } } 

    If I have not confused anything - such a minimum manifest is enough to simply display static files.

    In order to add an application in chrome, you need to publish it in the app store, but for chrome it is not necessary.

  2. Local server. The network has enough lightweight web servers that do not require installation and which can give out static files at some URL of the form http://127.0.0.1:8081/ .

    Or, on the contrary, you can make an application that requires installation and during this installation itself raises the site on IIS. It is not so difficult to raise a static site, it is more difficult to install IIS itself automatically (this is definitely possible, but I don’t remember how).

  3. Built-in browser. If you embed chromium in your application, you can "slip" any files on it using a non-standard scheme. Or on the standard - but setting all the necessary flags.

    From ready-made solutions to hear Electron . Among other features, Electron allows locally stored "client" code to use the entire Node.js API.

  • Thank you for such a detailed answer, but unfortunately, it does not correspond to the essence of the question - Vasya Shmarovoz
  • The user is the usual Zinnaida Ivanovna, the owner of some small LLC, which has its own local network. She just yesterday sysadmin told that there are good browsers in addition to IE. And now she had this SPA on the desktop (after she created the necessary xml with the contents through the program). And before giving it to the sysadmin, so that he uploads to the local server, she wants to open index.html herself to check it. But chrome, which she said yesterday, does not load xml, as a result a blank page opens - Vasya Shmarovoz
  • In the specific case, the user should not install any third-party software. The question was created to find out if there is any workaround for loading xml, or native ways to connect it locally - Vasya Shmarovoz
  • @VasyaShmarovoz and where did Zinanaida Ivanovna get index.html from the desktop? And where did she get the program that generates this xml? - Pavel Mayorov
  • one
    You were told from the very beginning, was it really so difficult to understand. - Ghringo