您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

JS 实现图片直接下载示例代码

作者:佚名    责任编辑:admin    更新时间:2022-06-22

本文为大家详细介绍下使用JS实现图片直接下载,具体实现代码如下,感兴趣的朋友可以参考下哈,希望对大家有所帮助   复制代码 代码如下:
<a href="picName.jpg" id=pic1 onclick="savepic();return false;" style="cursor:hand">点击下载</a>

 

复制代码 代码如下:


<script type="text/javascript">
function savepic() {
if (document.all.a1 == null) {
objIframe = document.createElement("IFRAME");
document.body.insertBefore(objIframe);
objIframe.outerHTML = "<iframe name=a1 style='width:400px;hieght:300px' src=" + imageName.href + "></iframe>";
re = setTimeout("savepic()", 1)
}
else {
clearTimeout(re)
pic = window.open(imageName.href, "a1")
pic.document.execCommand("SaveAs")
document.all.a1.removeNode(true)
}
}
</script>