开发者

How to download file using JavaScript [closed]

As it currently stands, this question is not a good fit 开发者_Go百科for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

How to download a file using JavaScript only?

Please don't give me answer like

"Change theMIMEin 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';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜