简体   繁体   中英

HTML download movie download link

I want a user to be able to hit a button which triggers a .mov file to download. Linking to the file its self just causes the movie to play in a new page.

I have tried this:

<a onclick="document.execCommand('SaveAs',true,'assets/files/mymovie.mov');" href="javascript:void(0);">

But this does not seem to work.

Can anyone point me in the right direction?

Thanks

您可以尝试html5下载属性。

<a href='assets/files/mymovie.mov' download>

In addition to Musa's answer:

Try setting the Content-Disposition header. You will need to set this up either in your server configuration, or let a executable script on your server do this (such as php):

Content-Disposition: attachment; filename="mymovie.mov"

if you're using a server side page to serve up content, by chance, then you can easily set the header of that page Content-Disposition: attachment and/or Content-Type:binary so that it kicks off a download.

otherwise, you can use download attribute in your <a> tag, which will only work in some browsers.

lastly, if you're feeling really heroic, you can go hack on your mime-types settings config file in your web server, in which you'd set the content disposition there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM