Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to download an image automatically using Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.46k
    Comment on it

    Hello Reader's! If you want to make your file download by execution of JS then you can use the code below:-

    var a = document.createElement('a');
    a.href = "/favicon.png"; //make the link of image
    a.download = "favicon.png";
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    

    Or you can use same function but another way:-

    var a = $("<a>").attr("href", "http://i.stack.imgur.com/L8rHf.png").attr("download", "img.png").appendTo("body");
    
    a[0].click();
    
    a.remove();
    

    In both cases, your file will download.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: