JS 实现图片直接下载示例代码
Posted 刘八哥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS 实现图片直接下载示例代码相关的知识,希望对你有一定的参考价值。
<a href="picName.jpg" id=pic1 onclick="savepic();return false;" style="cursor:hand">点击下载</a>
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) } }
以上是关于JS 实现图片直接下载示例代码的主要内容,如果未能解决你的问题,请参考以下文章