Carlota
Carlota

Reputation: 1237

javascript how to read a local file Denied access

I want to read a local file with javascript. I have the following function

$(function() {
        console.log("antes de readTextFile");
        readTextFile("file:///D:/carlota/eusruveyadmin/manuales/ficheropprueba.txt")

    });

    function readTextFile(file)
    {
        console.log("readFile principio");
        var rawFile = new XMLHttpRequest();
        rawFile.open("GET", file, false);
        rawFile.onreadystatechange = function ()
        {
            if(rawFile.readyState === 4)
            {
                if(rawFile.status === 200 || rawFile.status == 0)
                {
                    var allText = rawFile.responseText;
                    console.log("readFile fichero ",allText);
                }
            }
        }
        rawFile.send(null);
    }

In the console browser I have the following message "denied access"

enter image description here

I checked in the browser my file and I can see the file

enter image description here

How do I have to write the path of file?

Upvotes: 0

Views: 706

Answers (1)

Liviu Boboia
Liviu Boboia

Reputation: 1754

If you're using IE you need to set Settings/Tools->Internet Options->Security->Custom Level and change security settings under "Miscellaneous" set "Access data sources across domains" to Enable.

But it won't work for the users of your app, if they're using IE and don't have the same setting

Upvotes: 3

Related Questions