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.
Asked
Active
Viewed 1.2k times
3 Answers
5
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>
-
if i add this line in the html page then how will i click it using jquery or javascript – tushar singhal Jan 27 '17 at 09:37
-
1@tusharsinghal May be using this http://stackoverflow.com/questions/8192126/clicking-a-button-on-a-page-using-a-greasemonkey-userscript-in-chrome – Jan 28 '17 at 10:24
2
Try the HTML5 download attribute
<a href="myfile" download>click to download</a>
This opens a "save as" dialog regardless of file type.

Fandango68
- 4,461
- 4
- 39
- 74
2
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.net/balaji_mitkari/xpu9yrug/

Balaji Mitkari
- 80
- 3
-
Just be aware that this is supported only modern IE versions (from IE13 which is Edge) http://caniuse.com/#feat=download – Lauris Kuznecovs Jul 13 '17 at 19:24