Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery download image from url

const btn = document.getElementById('downloadImage');
const url = "https://s3-ap-southeast-1.amazonaws.com/tksproduction/bmtimages/pY3BnhPQYpTxasKfx.jpeg";

btn.addEventListener('click', (event) => {
  event.preventDefault();
  console.log('ABC')
  downloadImage(url);
})


function downloadImage(url) {
  fetch(url, {
    mode : 'no-cors',
  })
    .then(response => response.blob())
    .then(blob => {
    let blobUrl = window.URL.createObjectURL(blob);
    let a = document.createElement('a');
    a.download = url.replace(/^.*[/]/, '');
    a.href = blobUrl;
    document.body.appendChild(a);
    a.click();
    a.remove();
  })
}

Comment

PREVIOUS NEXT
Code Example
Javascript :: radio button in react 
Javascript :: java password regex 
Javascript :: Javascript find element with focus 
Javascript :: jest expect error to be thrown 
Javascript :: newtonsoft.json string to object 
Javascript :: keypress javascript 
Javascript :: jquery serialize form data to object 
Javascript :: datatable hide columns 
Javascript :: Round off a number to the next multiple of 5 using JavaScript 
Javascript :: dotenv nodejs 
Javascript :: javascript random int in range 
Javascript :: react flip move 
Javascript :: jquery selector checked 
Javascript :: xhr 
Javascript :: how to run angular application in visual studio code 
Javascript :: react native scrollview detect end 
Javascript :: get child routes using parent in angular 
Javascript :: video preview javascript 
Javascript :: d3.json() function 
Javascript :: javascript check if json file is empty 
Javascript :: material ui align icon with text 
Javascript :: replace array element javascript 
Javascript :: js is numeric 
Javascript :: js foreach .childern 
Javascript :: classlist.toggle 
Javascript :: read all file names of folder in react 
Javascript :: extract words from string js 
Javascript :: javascript pass all arguments to another function 
Javascript :: encodeuricomponent js 
Javascript :: radio button set value in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =