简体   繁体   English

如何强制下载mp3?

[英]How do I force to download the mp3?

Im working on a simple download Webside, but instead od downloading the mp3 it is opened in the browser.我正在做一个简单的 Webside 下载,但是 od 下载的是在浏览器中打开的 mp3。 How can I change this?我怎样才能改变这个?

<!doctype html>
<head>

    <link rel="stylesheet" href="css\stylesheet.css">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Webseite</title>
    
</head>

<style>


</style>

<body>
    <h1>Test</h1>
    <p>Test
    </p>
    <a href="download\audio.mp3" download="audio.mp3" download="true">Download link</a>
</body>

Thanks for the help:)谢谢您的帮助:)

Your code works fine, but您的代码工作正常,但是

  1. You don't need to use the download attribute twice, since most browsers will remove the last one.您不需要使用download属性两次,因为大多数浏览器会删除最后一个。
  2. The download attribute only works if the file refers to the same domain.只有当文件引用同一个域时,下载属性才有效。 Due to security reasons, it will not be possible to download external files in modern browsers.由于安全原因,无法在现代浏览器中下载外部文件。

If you want the user to download an external file, you could manually or automatically download that file on your server and link it to the same domain.如果您希望用户下载外部文件,您可以手动或自动将该文件下载到您的服务器上并将其链接到同一个域。 If you do, ensure that you are allowed to do this.如果这样做,请确保您被允许这样做。

  • download only works for same-origin URLs, or the blob: and data: schemes.下载仅适用于同源 URL 或 blob: 和 data: 方案。
  • If the Content-Disposition header has different information from the download attribute, resulting behavior may differ:如果 Content-Disposition header 具有与下载属性不同的信息,则结果行为可能会有所不同:
    • If the header specifies a filename, it takes priority over a filename specified in the download attribute.如果 header 指定了文件名,则它优先于下载属性中指定的文件名。
    • If the header specifies a disposition of inline, Chrome, and Firefox 82 and later, prioritize the attribute and treat it as a download.如果 header 指定 inline、Chrome 和 Firefox 82 及更高版本的配置,则优先考虑该属性并将其视为下载。 Firefox versions before 82 prioritize the header and will display the content inline. Firefox 82 之前的版本优先考虑 header 并将内联显示内容。

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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