L. Cornelius Dol
L. Cornelius Dol

Reputation: 64026

Download link for video file

I have a video for which I want to provide a download link. However, having created a simple <a href="myvideo.mp4">Download</a> tag, when I click on it (in Firefox & Chrome) it starts playing the video instead of allowing the video to be downloaded. Is there a way that works in all current browsers to force them to offer the save-as dialog?

Upvotes: 9

Views: 50136

Answers (2)

chirag lathiya
chirag lathiya

Reputation: 15

you should also try this.

            if (isVideo) {
            var div = document.createElement('div');
            div.className = "column";
            var vid = document.createElement('video');
            var source = document.createElement('source');

            source.type = "video/mp4";
            source.src = display_src;
            vid.appendChild(source);
            vid.poster;
            vid.controls = true;


            var alink = document.createElement('a');
            alink.href = display_src;
            alink.id = 'downlo_click';


            }

            alink.text = "Repost"
            // window.open(alink, '_self');
            div.appendChild(vid);
            div.appendChild(alink);
            document.getElementById('gamediv').appendChild(div)
            document.getElementById('downlo_click').addEventListener('click', function() {
                var x = new XMLHttpRequest();
                x.open("GET", display_src, true);
                x.responseType = 'blob';
                x.onload = function(e) {
                     download(x.response, "abcd.mp4", "video/mp4");
                }
                x.send();
                // window.open(alink, '_self');
                //   download("data:text/html,"display_src, display_src);
            });

        }

Upvotes: -2

Alexg2195
Alexg2195

Reputation: 605

Try using the download attribute.

<a href="myvideo.mp4" download>Download</a>

More at: http://www.w3schools.com/tags/att_a_download.asp

Upvotes: 11

Related Questions