Home  >  Article  >  Web Front-end  >  How to Open Local Files in Chrome: Bypassing the "Not Allowed to Load Local Resource" Error?

How to Open Local Files in Chrome: Bypassing the "Not Allowed to Load Local Resource" Error?

Linda Hamilton
Linda HamiltonOriginal
2024-11-17 09:44:03780browse

How to Open Local Files in Chrome: Bypassing the

Open Local Files in Chrome: Bypassing "Not Allowed to Load Local Resource" Error

Encountering the "Not allowed to load local resource" error when attempting to open local files in Google Chrome? Here's an alternative solution that circumvents this restriction:

By default, Chrome's security measures prevent direct access to local files. However, using a simple utility like "Web Server for Chrome" allows you to host local resources on a temporary server. Here's how it works:

Install "Web Server for Chrome"

  • Visit the Chrome Web Store and install the "Web Server for Chrome" extension.
  • Open the extension's options and choose a file system folder to serve.

Configure Server Settings

  • Choose an available port number (e.g., 8000) for the server to use.
  • Start the server by clicking the "Start" button.

Access Local Files

  • Navigate to the following URL in Chrome: http://127.0.0.1:port_number/ (e.g., http://127.0.0.1:8000/).
  • This URL will display the files within the selected folder.

Using the Solution

  • Modify the sample code provided by entering the URL of the local file as follows:
function run() {
  var URL = "http://127.0.0.1:8000/C:2.jpg";
  window.open(URL, null);
}
run();
  • This will instruct Chrome to load the local image from the local server instead of the file path, bypassing the security restriction.

The above is the detailed content of How to Open Local Files in Chrome: Bypassing the "Not Allowed to Load Local Resource" Error?. 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