Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Easy REACT download image

function App() {
  const download = e => {
    console.log(e.target.href);
    fetch(e.target.href, {
      method: "GET",
      headers: {}
    })
      .then(response => {
        response.arrayBuffer().then(function(buffer) {
          const url = window.URL.createObjectURL(new Blob([buffer]));
          const link = document.createElement("a");
          link.href = url;
          link.setAttribute("download", "image.png"); //or any other extension
          document.body.appendChild(link);
          link.click();
        });
      })
      .catch(err => {
        console.log(err);
      });
  };
  return (
    <div className="App">
      <a
        href="https://upload.wikimedia.org/wikipedia/en/6/6b/Hello_Web_Series_%28Wordmark%29_Logo.png"
        download
        onClick={e => download(e)}
      >
        <i className="fa fa-download" />
        download
      </a>
    </div>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how set defualt image for dropify 
Javascript :: javascript set input value 
Javascript :: how remove the spaces from the string, then return the resultant string 
Javascript :: javascript remove duplicates 
Javascript :: javascript keyup event enter key 
Javascript :: angular pipe percentage 
Javascript :: classiceditor is not defined using npm 
Javascript :: checkbox jquery checked 
Javascript :: add on click to div using jquery 
Javascript :: cookie clicker hack extension 
Javascript :: quasar change port 
Javascript :: react-native navigation screen props 
Javascript :: make input not editable for user js 
Javascript :: array contains method 
Javascript :: react native modal close when click outside 
Javascript :: how to convert name to initials in javascript 
Javascript :: react native only 1 corner rounded 
Javascript :: if text exists in element using javascript 
Javascript :: two array in one js 
Javascript :: Summernote keyup event jquery 
Javascript :: tailwind content for nextjs 
Javascript :: javascript string normalize method 
Javascript :: js copy array into another 
Javascript :: socket.io how do i get a list of connected sockets clients 
Javascript :: discord.js checking channel permissions 
Javascript :: add toaster in angular 
Javascript :: how to call function from parent component in child component vue 
Javascript :: react webpack.config.js 
Javascript :: parsley js decimal 
Javascript :: discordjs v13 get message content 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =