Open the file using javascript, on the client side

In my application, I want to open a file that exists on the client machine. I created two applications: a desktop and a web application. When a user installs a desktop application, there are some files that are copied to his installation path, and I want to open these files from my web application using javascript.

+3
source share
5 answers

The browser is isolated from the host computer (isolated) for security reasons.

The only way the browser can access local files (other than those inside the sandbox, that is, cookies and cache) is an HTML file control element that is explicitly used by the user.

+3
source

. JavaScript, JavaScript.

ActiveX JavaScript. IE .

0

?

<script>
var oRequest;

if(document.all) {
   // Internet Explorer
   oRequest = new ActiveXObject("Microsoft.XMLHTTP")
}
else {
   // Mozilla
   oRequest = new XMLHttpRequest();
}


oRequest.open("GET", "file:///C:/myLocalFile.txt", false);
oRequest.send(null);
textToBeWritten = oRequest.responseText;

document.write(textToBeWritten);
</script>
0

As Oded said for security reasons, this is not possible, saying that if you already have the application installed on the client computer, you can pass parameters to it and execute the application, in this case you will transfer the file URI to the application so that it opens on their machine, but I don’t see how this happens with-in the browser.

0
source

Source: https://habr.com/ru/post/1794659/


All Articles