使用Javascript / jQuery下载文件

本文翻译自: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: 安德鲁的答案的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值