Home >Web Front-end >JS Tutorial >How to Allow Local File XMLHttpRequest Requests in Google Chrome?

How to Allow Local File XMLHttpRequest Requests in Google Chrome?

Barbara Streisand
Barbara StreisandOriginal
2024-11-14 19:23:02499browse

How to Allow Local File XMLHttpRequest Requests in Google Chrome?

Overcoming XMLHttpRequest Restrictions in Local Files for Google Chrome

XMLHttpRequest requests from local files often encounter Access-Control-Allow-Origin violations, hindering data retrieval from remote URLs. However, it's possible to configure Google Chrome to allow such requests, enabling scripted local web pages to access remote content.

Solution:

Instead of using the potentially risky --disable-web-security switch, employ the --allow-file-access-from-files switch. This alternative addresses the security concerns while allowing XMLHttpRequest to access files from other local files.

Usage:

  • Windows: chrome.exe --allow-file-access-from-files
  • Mac: open /Applications/Google Chrome.app/ --args --allow-file-access-from-files

Additional Notes:

  • For safety, close all running Chrome instances before executing these commands.
  • The --allow-file-access-from-files feature has been discussed in various Chromium bug reports and forums.
  • This configuration allows XMLHttpRequest requests from local files to remote URLs, providing flexibility for local web pages.

The above is the detailed content of How to Allow Local File XMLHttpRequest Requests in Google 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