js实现给定图片路径自动下载

js实现图片自动下载

1.添加img标签

<img id='downImg' src='' style='display: none;' />

2.调用方法download

    //图片路径
    var src = './1.png';
    //下载保存文件名
    var imgname = 'testImg.jpg';

    function download(src,imgname) {
        $('#downImg').attr('src', src);
        var img = $('#downImg').attr("src");
        var alink = document.createElement("a");
        alink.href = img;
        alink.download = imgname;
        alink.click();
    }

You may also like...


Warning: Division by zero in /var/www/html/giserdqy/wp-includes/comment-template.php on line 1457

2 Responses

  1. 匿名说道:

    火狐上不能下载。。

发表评论