在<a> tag doesn&#39;t work when file URL called from sub domain

时间:2018-05-22 06:57:54

标签: html css html5

I have a blog here中下载属性,其中我使用了锚文件标记(<a>),其中包含HTML文件的download属性:

<a href="http://www.idevelopweb.site/newsletters/welcome-simple/welcome-simple.html" download>Download it here <i class="fa fa-download" aria-hidden="true"></i></a>

截图:

Screenshot of link to download

预期:用户点击时,应打开对话框下载文件。

但是,它会导航到该文件。 AFAIK,它早先工作。不确定发生了什么,或者我错过了什么?根据{{​​3}},&#34; .html&#34;文件是允许的。

如果不使用JavaScript,我们将非常感谢您的帮助。

修改 此博客位于w3schools example,我正在调用subdomain (http://blog.idevelopweb.site/)中的HTML文件,因此我使用了绝对路径。

4 个答案:

答案 0 :(得分:2)

我可能会引导您here

您的问题与下载属性的原始政策相同。所以要么使用相同的URL或相对路径。

答案 1 :(得分:1)

点击链接时下载文件(而不是导航到文件):

<a href="link" download="logo">

注意:Edge版本12,IE,Safari 10(及更早版本)或Opera版本12(及更早版本)不支持下载属性

答案 2 :(得分:0)

在您的代码中

<a href="http://www.idevelopweb.site/newsletters/welcome-simple/welcome-simple.html" download>Download it here <i class="fa fa-download" aria-hidden="true"></i></a>

href包含网页的链接,而不是必须下载的数据,图像或文件。网页不能使用锚标记的下载属性下载。因此它应该是格式:

<a href= "--link of image or file to be downloaded--"  download > Download </a>

例如:

<a href="/images/myw3schoolsimage.jpg" download> Download </a>

下载myw3schoolsimage.jpg图片

答案 3 :(得分:0)

尝试使用下载属性中的链接:

<a href="" download="link_to_file_to_download">Some text</a>