How to download file using JavaScript [closed]
How to download a file using JavaScript only?
Please don't give me answer like
"Change the
MIME
in the sever"
or
window.open(
URL
,"_blank")
Because I know there are another solutions. Thanks.
EDIT:
The file I want to download is a.JSON
file.You can dynamically create an iframe and set its location to the URL you wish to download.
var f = document.createElement("iframe");
f.setAttribute("id", "theFrame");
document.body.appendChild(f);
document.getElementById("theFrame").location = 'http://www.example.com/yourfile.doc';
Not sure if the above works properly. If not, try setting it by src
instead of location
in the last line:
document.getElementById("theFrame").src = 'http://www.example.com/yourfile.doc';
精彩评论