Downloading Image Using Javascript

Viewed 21

I'm Trying to download the image using filesaver.js library using the following code.

function downloadImage() {     
    var canvas =document.getElementById('canvas');
    canvas.toBlob(function(blob){
        saveAs(blob,'image.png');
    })
}

But when I Press the button it gives the error :

Uncaught DOMException: Failed to execute 'toBlob' on 'HTMLCanvasElement': Tainted canvases may not be exported. at downloadImage

I tried using crossorigin="anonymous" in image tags but then it does not load images.

Please can someone guide me a solution

0 Answers
Related