本文翻译自:Download File Using Javascript/jQuery
I have a very similar requirement specified here . 我在这里指定了非常相似的要求。
I need to have the user's browser start a download manually when $('a#someID').click();
我需要让用户的浏览器在$('a#someID').click();
时手动开始下载$('a#someID').click();
But I cannot use the window.href
method, since it replaces the current page contents with the file you're trying to download. 但我无法使用window.href
方法,因为它将当前页面内容替换为您尝试下载的文件。
Instead I want to open the download in new window/tab. 相反,我想在新窗口/选项卡中打开下载。 How is this possible? 这怎么可能?
#1楼
参考:https://stackoom.com/question/FjLT/使用Javascript-jQuery下载文件
#2楼
If you are already using jQuery, you could take adventage of it to produce a smaller snippet 如果您已经在使用jQuery,那么您可以利用jQuery来生成更小的代码片段
A jQuery version of Andrew's answer: 安德鲁的答案的