[Tool] Local page in Chrome, using XMLHttpRequest to read local archive problem scenarios
Developers can use the IDE's capabilities to debug the program to a mobile phone or emulator when developing Cordova, a hybrid app that uses Web content as a UI. But in my experience, to view HTML page elements, watch CSS style inheritance, the most handy developer tool is chrome. At this point, if the developer chooses to simulate the hybrid APP via Chrome, the local page is loaded in the file to debug the error, and XMLHttpRequest is used on the page to load the local file (ex: Angularjs Templateurl), the following error message will appear on Chrome:
Failed to execute ‘send‘ on ‘XMLHttpRequest‘: Failed to load ‘file:///C:/Users/Clark/Desktop/XhrFileAccessSample/content.txt‘.
This error occurs because Chrome prohibits local pages from using XMLHttpRequest to read local files based on security considerations. This also causes the same HTML page content, the deployment to the mobile phone or emulator can normally use XMLHttpRequest, and on Chrome do not use the normal XMLHttpRequest.
Solution Solutions
In order for local Web pages to be executed on Chrome, XMLHttpRequest can be used to read local archive content as usual. Developers can open the XMLHttpRequest read file feature by adding the "--allow-file-access-from-files" parameter on the shortcut to launch Chrome. Using this shortcut, you can use XMLHttpRequest to read the local archive content as soon as you enable Chrome to execute the local page.
Shortcut settings
Index.html
<!DOCTYPE html>
Content.txt
Clark
Sample DownloadSample download: Click here to download
[Tool] local pages within Chrome, using XMLHttpRequest to read local archives