[英]HTML download movie download link
I want a user to be able to hit a button which triggers a .mov file to download. 我希望用户能够点击触发.mov文件下载的按钮。 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: 除了Musa的答案:
Try setting the Content-Disposition
header. 尝试设置
Content-Disposition
标头。 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): 您将需要在服务器配置中进行设置,或者让服务器上的可执行脚本执行此操作(例如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. 如果您偶然使用服务器端页面来提供内容,则可以轻松设置该页面的标题
Content-Disposition: attachment
和/或Content-Type:binary
以便开始下载。
otherwise, you can use download attribute in your <a>
tag, which will only work in some browsers. 否则,您可以在
<a>
标记中使用download属性,该属性仅在某些浏览器中有效。
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. 最后,如果您觉得自己很英勇,可以在Web服务器上修改mime-types设置配置文件,在其中设置内容配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.