0

I am trying to screenshot and download it to server, but I am still getting an error. It's using Wordpress by the way.

Uncaught (in promise) Provided element is not within a Document

jQuery:

<script>
$('#save').click(function(){
    html2canvas($('#capture'),
    {
        onrendered: function (canvas) {
        var a = document.createElement('a');

        a.href = canvas.toDataURL("image/jpeg").replace("image/jpeg", "image/octet-stream");
        a.download = 'somefilename.jpg';
        a.click();
        }
    });
    });
</script>
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
YSS ID
  • 1
  • 1

1 Answers1

0

You need to append the element a once it has been created.

document.body.appendChild(a);

After creating the element, the a tag is not found on the document when you trigger a.click() because you are not appending it anywhere.

Ashish Yadav
  • 1,901
  • 2
  • 17
  • 23