示例代码:
javascriptfunction downloadImage(imageUrl, imageName) {
var a = document.createElement('a');
a.href = imageUrl;
a.download = imageName;
a.click();
}
// 使用
javascriptdownloadImage('http://example.com/example.jpg', 'example.jpg');
这种方法可能受到浏览器的安全限制,特别是在跨域请求的情况下。如果图片服务器不允许文件下载,那么这种方法可能会失败。