我在链接中使用下载属性:
<a style="color:white" download="myimage" href="images/myimage.jpg">Download image</a>
它在几乎所有浏览器中都运行良好。这意味着,如果我点击链接,图像会自动下载。我在我的 mac 上的 safari 10.1.2 中测试了它,它工作正常。
但是在我使用 safari 10.0.3 的 friend mac 上,它不起作用。他是说图片只能在新窗口中打开但不能下载。
为什么会发生这种情况,我该怎么做才能让它在任何地方都能正常工作?
最佳答案
根据 https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_1.html , 它是在 Safari 10.1 中添加的:
HTML5 Download Attribute The download attribute for anchor elements indicates that the link target is a download link that downloads a file, instead of a navigational link. When you click a a link with the download attribute, the target is downloaded as a file. Optionally, the value of the download attribute provides the suggested name of the file.
尽管从我自己的测试来看,它似乎在 iOS Safari 11.1 中不可用,这让我有点困惑。基于它们相似的版本编号,我希望它们在标准支持方面是平等的。
关于html - 下载属性在 safari 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46690722/