首頁  >  文章  >  web前端  >  javascript實作將檔案儲存到本地方法匯總_javascript技巧

javascript實作將檔案儲存到本地方法匯總_javascript技巧

WBOY
WBOY原創
2016-05-16 15:49:031482瀏覽

以下是保存一張圖片為範例,程式碼來自網絡,希望能夠帶給大家一定的幫助,程式碼如下:

<script type="text/javascript"> 
function saveFile(imgUrl) 
{ 
 var oPop=window.open(imgUrl,"","width=1, height=1, top=5000, left=5000"); 
 for(;oPop.document.readyState != "complete"; ) 
 { 
  if(oPop.document.readyState=="complete")break; 
 } 
 oPop.document.execCommand("SaveAs"); 
 oPop.close(); 
} 
</script> 
</head>
<body>
<img src="../mytest.jpg" id="theimage" border="0"> 
<a href="#" onclick="saveFile(document.getElementById('theimage').src)"> 点击这里下载图片 </a> 
</body>
</html>

方法二:

function SaveAs5(imgURL)
  {
  var Pop = window.open(imgURL,"","width=1, height=1, top=5000, left=5000");
  for(; oPop.document.readyState != "complete"; )
  {
  if (oPop.document.readyState == "complete")break;
  }
  oPop.document.execCommand("SaveAs");
  oPop.close();
  }

<img src="t_screenshot_17616.jpg" id="DemoImg" border="0" onclick="SaveAs5(this.src)">

方法三:

function SaveAs5(imgURL)
  {
  var Pop = window.open(imgURL,"","width=1, height=1, top=5000, left=5000");
  for(; oPop.document.readyState != "complete"; )
  {
  if (oPop.document.readyState == "complete")break;
  }
  oPop.document.execCommand("SaveAs");
  oPop.close();
  }

<img src="../t_screenshot_17616.jpg" id="DemoImg" border="0"> 
<a href="#" onclick="SaveAs5(document.getElementById('DemoImg').src)"> 点击这里下载图片 </a> 

以上所述就是本文的全部內容了,希望大家能夠喜歡。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn