Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Html2Canvas screenshot and download

function capture() {
    const captureElement = document.querySelector('#capture')
    html2canvas(captureElement)
        .then(canvas => {
            canvas.style.display = 'none'
            document.body.appendChild(canvas)
            return canvas
        })
        .then(canvas => {
            const image = canvas.toDataURL('image/png').replace('image/png', 'image/octet-stream')
            const a = document.createElement('a')
            a.setAttribute('download', 'my-image.png')
            a.setAttribute('href', image)
            a.click()
            canvas.remove()
        })
}

const btn = document.querySelector('#btn')
btn.addEventListener('click', capture)
Comment

PREVIOUS NEXT
Code Example
Javascript :: split string in angular 8 
Javascript :: youtube video regex 
Javascript :: javascript array functions 
Javascript :: js how to remove # from any url using js 
Javascript :: share link to whatsapp javascript 
Javascript :: express return json 
Javascript :: how to get enum item name in javascript 
Javascript :: javascript - get the filename and extension from input type=file 
Javascript :: how to split text into array javascript 
Javascript :: .call javascript 
Javascript :: Extract phone number from text regex 
Javascript :: remove array elements javascript 
Javascript :: cdn react 
Javascript :: killall node windows 
Javascript :: REACT-ICONS reduce thickness 
Javascript :: adding border in react native 
Javascript :: regex to ignore white spaces js 
Javascript :: emit resize event in angular 
Javascript :: mysql json array contains 
Javascript :: mongodb update many 
Javascript :: nested for loops javascript 
Javascript :: get name of day javascript 
Javascript :: JS ignoring accents 
Javascript :: js detect link in string 
Javascript :: use js to save data in laravel using route 
Javascript :: how to stop browser back js 
Javascript :: generate random date 
Javascript :: how to use if in setstate 
Javascript :: javascript sort array of objects by key value 
Javascript :: Select All Elements With A Class getElementsByClassName 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =