使用下载按钮从页面下载图像

Download an image from a page using download button

本文关键字:下载 图像 按钮      更新时间:2023-09-26

我在一个页面上有一个图像和一个下载按钮。我想点击下载按钮,图像需要下载(*它可以是任何格式)。

下面是图片和下载按钮的代码
<Style>
.results img {
position: absolute;
top: 33%; 
left: 25.5%;
width: 50%;
height: auto;
.button img{
position: absolute;
left: 50%;
top: 94.5%;
</style>
<div class="results">
<img src="Images'pic.png">
</div>
<div class="Button">
<input id="test1" name="test1" type="image" src="images/download.png" value="myValue" alt="" onClick=""></div>

谁能建议我一个JavaScript解决方案来实现这一点。

#image{
 
    float:left;
}
#dwnld{
    float:left;
}
.button {
    appearance: button;
    -moz-appearance: button;
    -webkit-appearance: button;
    text-decoration: none; font: menu; color: ButtonText;
    display: inline-block; padding: 2px 8px;
    font-size: 15px;
}
<div id="download">
    <img src="https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" id="image" />
    <a class="button" href="https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" download="google.png">Download image</a>
</div>