[Tool] Local pages in Chrome, using XMLHttpRequest to read local files

Source: Internet
Author: User

[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 Download

Sample download: Click here to download

[Tool] local pages within Chrome, using XMLHttpRequest to read local archives

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.