现在的位置: 首页 > 综合 > 正文

JS实现图片下载

2012年08月23日 ⁄ 综合 ⁄ 共 510字 ⁄ 字号 评论关闭

<a href="javascript:DownLoad('images/1.jpg')">下载</a>
 <script>
  var frm = null;
  var timer = null
  function DownLoad(url)
  {
    frm = document.createElement("IFRAME");
    frm.style.display = "none";
    document.body.appendChild(frm);
    frm.contentWindow.location.href = url
   
    timer =  setInterval(checkload,200);
  
  }
  function checkload(){
    if( frm.contentWindow.document.readyState =="complete")
    {
        frm.contentWindow.document.execCommand("SaveAs");
       clearInterval(timer)}
       document.body.removeChild(frm);
    }
 </script>

抱歉!评论已关闭.