It is necessary that when you open the page in the browser in the text box, you can enter the URL of the file, after which JavaScript downloaded it, processed and displayed. I tried to do it via XmlHttpRequest like this:

var request = new XMLHttpRequest(); request.open('GET', url, false); request.overrideMimeType('text\/plain; charset=x-user-defined'); request.send(); var data; if(request.status === 200) { return stringToByteBufferData(request.response); } 

But it only works if the page is on the same domain as the file. Is it possible to make it download a file via any direct link?

PS The request is synchronous, because it is more convenient for me, and the delay is insignificant - the file processing takes an order of magnitude more than downloading it.

  • one
    only if you have access to the server and the ability to install Access-Control-Allow-Origin - Grundy
  • And without access in any way? After all, I can just take and download the file with my hands, why does javascript need something else for this? I googled, they write that it’s so safer, but I still don’t understand what could be dangerous and why not let the script author decide? Another thing, if there is authorization using cookies, but I just need to get stupidly the contents of the file for a direct link. Well, or assume that one server has access. What do you need to do so that at least you can download files from outside the script? Where to register this Access-Control-Allow-Origin? - devoln
  • limiting XMLHttpRequest , where to register - in response to the server. depends more specifically on the server - Grundy
  • Somewhere in apache or nginx config? - devoln 7:09 pm

0