Pingo
Pingo

Reputation: 533

How to Download video tag using JS?

I have a link that I want to download the video from.

<video name="media">
 <source src="https://foo.bar" type="video/mp4">
</video>

I want to be able to download the vid to the user storage using javascript.

Upvotes: 7

Views: 24400

Answers (2)

ryanpcmcquen
ryanpcmcquen

Reputation: 6455

Just add an anchor tag with the same link and a download attribute:

<a href="https://foo.bar" download>
    Download Me!
</a>

Upvotes: 7

Achraf
Achraf

Reputation: 1520

Since you have the link, you can trigger it manually.

var a = $("<a>")
    .attr("href", "LINK HERE")
    .attr("download", "vid.mp4")
    .appendTo("body");

a[0].click();

a.remove();

Upvotes: 5

Related Questions