国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

javascript - js怎麼實作保存圖片到本地?
巴扎黑
巴扎黑 2017-06-15 09:22:51
0
3
1124

點擊a標籤時,下載圖片怎麼實現(xiàn)?

<img src="images/123.png" alt="">
        <a href="#">下載圖片</a>
巴扎黑
巴扎黑

全部回覆(3)
阿神

兩種思路:
1.

    <html>  
     <head>  
      <title> 通過js保存圖片到本地 </title>  
      <meta name="Generator" content="EditPlus">  
      <meta name="Author" content="">  
      <meta name="Keywords" content="">  
      <meta name="Description" content="">  
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>  
    </head>  
 <body>  
  <input type="button" value="download image" onclick="DownLoadReportIMG('http://www.oursss.com/uploads/photo/1045_2590.jpg?rd=0.9961522558898981');">    
 </body>  
</html> 
  function DownLoadReportIMG(imgPathURL) {
        //如果隱藏IFRAME不存在,則添加
        if (!document.getElementById(“IframeReportImg”))
        $(‘‘).appendTo(“body”);
        
        if (document.all.IframeReportImg.src != imgPathURL) {
            //加載圖片
            document.all.IframeReportImg.src = imgPathURL;
        }
        else {
            //圖片直接另存為
            DoSaveAsIMG();
        }
    }
    function DoSaveAsIMG() {
        if (document.all.IframeReportImg.src != “about:blank”)
        document.frames(“IframeReportImg”).document.execCommand(“SaveAs”);
    }
    
    
    
    
    
 
2.第二種思路,使用獲取img對象,然后通過ajax+fromData發(fā)送到服務端,然后發(fā)起請求下載該圖片

-------------暫時想到這兩種,沒有找到js寫文件的權限,想到在補充
學霸

雷雷

代言

a標籤的href指向檔案位址

<a href="images/123.png">下載圖片</a>
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板