Home  >  Article  >  Web Front-end  >  How to Access Local Files in Chrome After File Access Restrictions?

How to Access Local Files in Chrome After File Access Restrictions?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-17 10:12:03948browse

How to Access Local Files in Chrome After File Access Restrictions?

File Access Denied in Chrome: Unable to Load Local Resource

In JavaScript, accessing local files directly through protocols like "file://" has been restricted in Chrome versions 52 and above for security reasons. This causes difficulties when attempting to open local images or other resources.

Example:

function run(){
    var URL = "file:///C:<pre class="brush:php;toolbar:false">function run(){
    var URL = "http://127.0.0.1:8887/C:2.jpg";
    window.open(URL, null);
}
run();
2.jpg"; window.open(URL, null); } run();

Suggested Solution:

To resolve this issue, one suitable solution is to use a simple and lightweight HTTP server like "Web Server for Chrome". This browser extension allows you to host local files and access them through a web address (e.g., 127.0.0.1:port).

Instructions:

  1. Install the "Web Server for Chrome" extension from the Chrome Web Store.
  2. Open the Windows Explorer folder where your local files are located.
  3. In the extension, select the "Share Address" option.
  4. Copy the provided URL (e.g., 127.0.0.1:8887).
  5. Update your JavaScript to open the local file using the URL provided by the server:

This method allows Chrome users to access local files securely and conveniently without compromising security or usability.

The above is the detailed content of How to Access Local Files in Chrome After File Access Restrictions?. 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