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:
Additionally, the Google product forums offer insights on this topic:
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!