Html2canvas: Uncaught (in promise) 提供的元素不在文档中

创建于 2017-12-14  ·  23评论  ·  资料来源: niklasvh/html2canvas

这个错误是什么意思? 以及如何修复它

Needs More Information

最有用的评论

如果您使用 jQuery 查找 DIV 使用
html2canvas($("#element")[0]).then(function(canvas) {
$("#element-out").append(canvas);
});

所有23条评论

您尝试呈现的元素不在文档 DOM 中

那么如何解决这个问题呢?

0.5 很好,但是当我升级到 1 时出现此错误

请分享一个关于 jsfiddle 的例子

我试图在 HTML 正文之后加载 html2canvas js(版本 1)和我的应用程序 js,这个问题已经为我解决了。

有没有人解决了这个问题,我在 ASP.Net MVC cshtml 页面中使用时遇到了同样的问题。

如果您使用 jQuery 查找 DIV 使用
html2canvas($("#element")[0]).then(function(canvas) {
$("#element-out").append(canvas);
});

但是我无法使用 html2canvas 拍摄谷歌地图的图像(所有地图图像都没有出现),任何人都可以帮助我如何在 cshtml 中做同样的事情吗???

@cjcortez @RaghavPrabhu是否为您修复了上面的 smartbepl 解决方案,假设您使用的是 jQuery 或其他一些提供元素列表而不是单个Element

这对我有用!
html2canvas($('#div').get(0)).then(函数(画布){
控制台日志(画布);
});

谢谢它有效

@jeremielodi谢谢,这让我发疯了!

我尝试了与上述类似的代码,但也许我得到的错误不是很相关:Uncaught (in promise) undefined... Promise denied (async)

我遇到了完全相同的问题 - 我想在单击按钮时调用 HTML2Canvas。 无论我如何编写 HTML2Canvas 调用,我都会收到“Uncaught (in promise) undefined...Promise denied (async)”错误。 最后,我对 Promise 的工作原理有了一些了解,并发现解决方案是添加一个捕获:

function myFunction() {
    html2canvas(document.querySelector("#capture")).then(canvas => {          
            var base64encodedstring = canvas.toDataURL("image/jpeg", 1).replace("data:image/jpeg;base64,", "");
            j$("[id$='inputHidden']").val(base64encodedstring);
            console.log('Saving...');
            mySaveFunction();
        })
        .catch(function (error) {
            /* This is fired when the promise executes without the DOM */    
        });
}

警告的话,我是一个 javascript 新手,对 Promise 的工作原理知之甚少。 如果我在函数之外使用它,我的代码在没有 .catch() 的情况下运行良好。 我假设不知何故,当您封装它时,它不再具有正确的 DOM 访问权限并且承诺失败。

@ikemike这可以帮助你
```html


html2canvas


@niklasvh使用最新版本的 html2canvas 我得到 Uncaught (in promise): undefined error。 你能帮我么。

image

image

ths,它有效

这对我来说很好用:

function downloadURI(uri, name) {
    var link = document.createElement("a");

    link.download = name;
    link.href = uri;
    document.body.appendChild(link);
    link.click();
    clearDynamicLink(link); 
}

function DownloadAsImage() {
    var element = $("#table-card")[0];
    html2canvas(element).then(function (canvas) {
        var myImage = canvas.toDataURL();
        downloadURI(myImage, "cartao-virtual.png");
    });
}

在 chrome 中,它工作正常,但在 IE11 中,不起作用...... T_T;

未捕获(承诺):未定义错误

@bandacs您找到解决方案了吗? 我在你的屏幕截图中得到了确切的错误。

我正在使用 1.0 alpha 12 版本,但我遇到了同样的问题。 我已经尝试了所有这些解决方案。

我已经通过@smartbepl 尝试过这个解决方案
html2canvas($("#element")[0]).then(function(canvas) {
$("#element-out").append(canvas);
});

我通过@jeremielodi 尝试过这个
html2canvas($('#div').get(0)).then(函数(画布){
控制台日志(画布);
});

我还尝试了 Leandrocgsi 解决方案,并尝试按照@ikemike 的建议添加一个捕获。

为了简化它并确保所有元素都加载到 DOM 上,我放置了一个名为 take_screenshot() 的函数。

函数 take_screenshot()
{
html2canvas($(".image__container")[0]).then(canvas => {
console.log('请工作,我正在失去理智');
});
}
然后我直接从 javascript 控制台调用 take_screenshot() 以确保加载所有内容。
我得到了同样的错误 Uncaught (in promise) undefined。

我遇到了与https://github.com/niklasvh/html2canvas/issues/1313#issuecomment -377132089 完全相同的问题
任何人都可以找到有关此问题的解决方案吗?

为什么我在cheerio失败了?

   .get(url)
   .end((err, res) => {
       cheerio.load(res.text)
       html2Canvas($('#statuses').get(0), {
           allowTaint: true
       }).then(function(canvas) {})
})
Uncaught (in promise) Error: Element is not attached to a Document

现在还有另一个调用约定。
0.5 版需要数组中的节点,而您现在直接提供它。
0.5 版具有“onrendered”选项,而您现在使用“then”构造。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

celik75 picture celik75  ·  4评论

tjchambers32 picture tjchambers32  ·  3评论

yasergh picture yasergh  ·  5评论

koreanman picture koreanman  ·  4评论

anthonymejia picture anthonymejia  ·  4评论