Home > database >  HTML video automatically download
HTML video automatically download

Time:11-13

I want to use javascript to automatically download a video file given a url that contains the link to the video. So far I have tried the approach of using <a href='somelink' download> but when I click on the link it will open a new tab containing the video instead of downloading it. Is there a way to write a script that automatically does the job that the video tag control options does? Like the picture shown below, can I write javascript to trigger the event on the download button? Thanks.

enter image description here

CodePudding user response:

This might helpful.

document.getElementById("myCheck").click();
<a download="name_of_downloaded_file" href="https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" id="myCheck"> Clicking on this link will force download the file</a>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

Use target=”_blank” along with anchor tag with download option to prevent streaming files directly in browsers on desktop and android or iOS (iPhone) devices.

<a href='somelink' download target=”_blank”>

Here is the reference

  • Related