Home > Web Front-end > JS Tutorial > body text

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

Linda Hamilton
Release: 2024-11-17 09:44:03
Original
779 people have browsed it

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();
Copy after login
  • 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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template