Home >Web Front-end >JS Tutorial >How to Allow XMLHttpRequest Access to Remote URLs from Local Files in Chrome?

How to Allow XMLHttpRequest Access to Remote URLs from Local Files in Chrome?

Barbara Streisand
Barbara StreisandOriginal
2024-11-16 08:13:031018browse

How to Allow XMLHttpRequest Access to Remote URLs from Local Files in Chrome?

Allowing XMLHttpRequest Access to Remote URLs from Local Files in Google Chrome

When attempting to use XMLHttpRequest to load a URL from a local file in Google Chrome, it often fails due to Access-Control-Allow-Origin violations. This can be problematic for users working with local web pages.

Solution Using --allow-file-access-from-files Switch

To circumvent this issue, Google Chrome provides a command-line switch called --allow-file-access-from-files. This switch allows XMLHttpRequest to access files from other files.

Usage

To use this switch, ensure all running instances of Chrome are closed, then execute the following commands:

Windows:

chrome.exe --allow-file-access-from-files

Mac:

open /Applications/Google\ Chrome.app/ --args --allow-file-access-from-files

Important Note

Using the --allow-file-access-from-files switch disables certain security restrictions. It is crucial to maintain caution and avoid loading untrustworthy content from local files.

Further Information

For more discussion on this feature, refer to the following Chromium bug trackers:

  • https://bugs.chromium.org/p/chromium/issues/detail?id=37586
  • https://bugs.chromium.org/p/chromium/issues/detail?id=47416

Additionally, the Google product forums offer insights on this topic:

  • https://productforums.google.com/forum/#!topic/chrome/v177zA6LCKU

The above is the detailed content of How to Allow XMLHttpRequest Access to Remote URLs from Local Files in Chrome?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn