javascripthtml

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.


Solution

  • 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();