最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to force chrome to download files not opening them? - Stack Overflow

programmeradmin2浏览0评论

I am using window.location.href="link.mp4" in a userscript in chrome tampermonkey but rather than starting the download chrome is opening the file and starts playing it. I have a file link in a variable and i also use idm if there's any way to trigger the through idm.

I am using window.location.href="link.mp4" in a userscript in chrome tampermonkey but rather than starting the download chrome is opening the file and starts playing it. I have a file link in a variable and i also use idm if there's any way to trigger the through idm.

Share Improve this question edited Jan 27, 2017 at 9:28 tushar singhal asked Jan 27, 2017 at 6:18 tushar singhaltushar singhal 531 gold badge1 silver badge5 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

Did you try download attribute ?

Example Download file when clicking on the link (instead of navigating to the file):

<a href="/images/myw3schoolsimage.jpg" download>

http://www.w3schools./tags/att_a_download.asp

Try the HTML5 download attribute

<a href="myfile" download>click to download</a>

This opens a "save as" dialog regardless of file type.

The download attribute specifies that the target will be downloaded when a user clicks on the hyperlink.

<a href="filename.mp4" download>Download File</a>

Try working JSfiddle https://jsfiddle/balaji_mitkari/xpu9yrug/

发布评论

评论列表(0)

  1. 暂无评论