在我的html文件中,我希望有一个图像链接,当点击它时,它会开始下载到本地文件夹。通常情况下,要下载链接,我们必须右键单击然后选择另存为。
我尝试了以下方法:
var href = document.createElement("a");
href.setAttribute("href", url1);
href.appendChild(document.createTextNode("Image Download"));
href.setAttribute("download", "test.jpg");
contentDiv.appendChild(href);
但它仍然无法工作。我点击后,图片在浏览器中打开。
<a download="test.jpg" href="https://farm8.staticflickr.com/7555/29856053076_43cceef1b6_o.jpg">download</a>
我在火狐浏览器中尝试了这个,但它没有起作用。 - Santhoshhref="insert/path/(Where you want the user to save it to)"
这是什么意思?我的图片链接是https://farm8.staticflickr.com/7555/29856053076_43cceef1b6_o.jpg
。 - Santhosh<a download="test" href="https://farm8.staticflickr.com/7555/29856053076_43cceef1b6_o.jpg">download</a>
但它无效。 - Santhosh