如何将图像从页面保存到文件夹

时间:2018-04-14 20:23:42

标签: javascript jquery html5

我的index.html页面中有一张图片。我希望javascript或jquery通过单击按钮在我的文件夹中自动下载此图像。

<!DOCTYPE HTML>
<html>
<head>
   <title>save image from a page</title>
</head>

   <body>

   <img src="car.jpg"/>
   <button>save Image in my folder</button>
   <!-- the name of the folder is : (saveImage) :  and it is in the same 
   place with my index.html-->

   <script src="jquery-1.11.3.min.js"></script>
   <script>
   $("button").click(function()
   {
      // download image from the index.html to my folder (saveImage)
   });
  </script>

  </body>
  </html>

1 个答案:

答案 0 :(得分:1)

我试过跟随并用firefox和chrome检查它。两种浏览器都很好用。使用HTML5“下载”属性到您的链接。

<!DOCTYPE HTML>
<html>
<head>
<title>save image from a page</title>
</head>
<body>
 <a style="display:none;" href="car.png" download>save Image in my folder     </a>
<img src="car.png"/>
<!-- the name of the folder is : (saveImage) :  and it is in the same 
place with my index.html-->
<button>save Image in my folder</button>
 <script src="jquery-1.11.3.min.js"></script>
<script>
$("button").click(function()
{
   $('a')[0].click();
});
</script>
</body>
</html>
相关问题