Home > Web Front-end > JS Tutorial > body text

Javascript implementation of saving files to local methods summary_javascript skills

WBOY
Release: 2016-05-16 15:49:03
Original
1479 people have browsed it

The following is an example of saving a picture. The code comes from the Internet. I hope it can bring some help to everyone. The code is as follows:

<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>
Copy after login

Method 2:

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

Copy after login

Method three:

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> 

Copy after login

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!