관리 메뉴

필사(筆寫)

자바스크립트로 크롬 다운로드 A 태그 만들기 본문

고민흔적

자바스크립트로 크롬 다운로드 A 태그 만들기

코딩필사 2022. 1. 24. 04:46
        const image = await fetch(url)
          .then(res => res.blob())
          .then(blob => URL.createObjectURL(blob))
          .catch(e => null)
        if (!image) { return result }
       
        const a = document.createElement("a")
        a.href = image
        a.download = `${fileName}`
        document.body.appendChild(a)
        a.click()

        setTimeout(() => {
          window.URL.revokeObjectURL(url)
          document.body.removeChild(a)
        }, 1)

 

데이터 가져와서, 처리해주는 구문 es6