Firefox refuses a relative path for local files

Viewed 704

I load a local html file from my windows 7 filesytem :

 file:///C:/Users/...etc.../myfile.html

Inside it, an existent file relative to the directory of myfile.html :

 ....load("../common/events.json");

Firefox refuses it, error at console :

    Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote 
    resource at file:///C:/Users/...etc.../common/events.json?timeshift=-60. (Reason: CORS request not http).

With link : https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSRequestNotHttp

So I set privacy.file_unique_origin to false in config and restarted Firefox : same issue

NB all is ok with ... IE 11 !

2 Answers

The security feature you disabled only blocks accessing files in the same or lower directory as the HTML document.

Accessing files is other directories (i.e. if your relative path starts with ../ or you use an absolute path) is always forbidden.

You could start your own local server:

python3 -m http.server

which tells you the port (e.g. Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/)).

Then something enter in browser address bar something like http://0.0.0.0:8000/C:/Users/...etc.../myfile.html.

The path is relative to the location where the server was started.

Related