Need to download the remote file into browser using javascript. I am having the url of the file. Download must happen in background
Asked
Active
Viewed 232 times
-4
-
1Download must happen in background -- you are trying to create backdoor when user visit your site? – Teddybugs Mar 25 '14 at 06:08
1 Answers
-1
No, JavaScript doesn't have access to writing files as this would be a huge security risk.
see Read/write to file using jQuery
IF you want to simply download the content and use it in the script, using jQuery it's very simple:
https://api.jquery.com/jQuery.ajax/
jQuery.ajax({
url: "your/file/here",
dataType: 'text', // you can also use xml, json, html here
success : function(data) {
console.log(data);
},
error : function(xhr, textStatus, errorThrown) {
console.log("ERROR: "+textStatus+", "+errorThrown);
},
async: true
});
-
i done that using jquery. Now i need to make download without showing that to the user to the specified location – user3318686 Mar 25 '14 at 18:02
-
What do you mean with "to the specific location"? Writing to the file system? This won't work with JavaScript (see above). – ivicaa Mar 25 '14 at 19:12