您的位置:首页 > Web前端 > JavaScript

javascript实现将文件保存到本地方法汇总

2015-07-26 00:00 801 查看

下面是保存一个图片为示例,代码来源于网络,希望能够给大家带来一定的帮助,代码如下:

<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>


以上所述就是本文的全部内容了,希望大家能够喜欢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: