zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

JS下载代码 实现 示例 图片 直接
2023-06-13 09:15:03 时间
复制代码代码如下:

<ahref="picName.jpg"id=pic1onclick="savepic();returnfalse;"style="cursor:hand">点击下载</a>

复制代码代码如下:

<scripttype="text/javascript">
functionsavepic(){
if(document.all.a1==null){
objIframe=document.createElement("IFRAME");
document.body.insertBefore(objIframe);
objIframe.outerHTML="<iframename=a1style="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>