<a> tag download attribute not working for mobile

时间:2018-07-02 03:46:59

标签: android html iphone download anchor

I have this anchor tag as below:

<a className="badge-link" href="./download/myapp-v1.1.0.apk" download="myapp-v1.1.0.apk">
   <img src="img/download-apk.png" alt=""/>
</a>

Just want to clarify that the apk file & website is hosted at a server and I'm downloading the file from there.

The download works on PC but on mobile it gets stuck at downloading status forever.

It doesn't show download progress at all.

I've tried closing the download manager & clearing its cache for android but I still get the same result.

How do I make this download work on android/iphone? Or is there any other alternatives?

4 个答案:

答案 0 :(得分:2)

问题似乎与href中指定的路径有关。尝试给出

之类的过时路径
  

http://somedomain.com/somefolder/somefile

    <a className="badge-link" onclick="startDownload('http://somedomain.com/somefolder/somefile')" download="myapp-v1.1.0.apk"> <img src="img/download-apk.png" alt=""/> </a>

//Js to open in the same tab
<script>function startDownload(url) { window.location.href = url; }
</script>

在返回文件的HTTP响应上,确保内容处置标头如下所示:

  

Content-Disposition:附件; filename = filename.extesion;

检查此内容以了解更多有关内容wiki-处置

只需测试一下,先提供一些第三方链接,然后再尝试使用您的

答案 1 :(得分:0)

我认为这是因为在PC上进行测试时,您的项目目录中包含apk。 但是您没有在移动设备上使用它。

答案 2 :(得分:0)

我认为在您的PC中,项目文件夹中具有该apk文件,但是在您的手机以及您的项目文件夹中,该apk文件均已丢失。 而且您也可以尝试以下代码

<a className="badge-link" href="download/myapp-v1.1.0.apk" download>
    <img src="img/download-apk.png" alt=""/>
</a>

答案 3 :(得分:0)

尝试一下

<a className="badge-link" href="http://somedomain.com/download/myapp-v1.1.0.apk" download="myapp-v1.1.0.apk"> 
  <img src="img/download-apk.png" alt=""/> 
</a>