【问题标题】:I'm getting index.ts:36 Uncaught (in promise) Error: Element is not attached to a Document我收到 index.ts:36 Uncaught (in promise) 错误:元素未附加到文档
【发布时间】:2020-08-18 10:11:44
【问题描述】:

我正在尝试截屏并将其下载到服务器,但我仍在获取 一个错误。顺便说一句,它使用的是 Wordpress。

未捕获(承诺)提供的元素不在文档中

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>

【问题讨论】:

标签: javascript jquery screenshot


【解决方案1】:

您需要在创建后附加元素a

document.body.appendChild(a);

创建元素后,当您触发a.click() 时,在文档中找不到a 标签,因为您没有将它附加到任何地方。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多