html2canvasc的id,html2canvas不呈现CDN图像

本文探讨了如何使用html2canvas获取屏幕截图时遇到的问题,特别是CDN链接的图片无法正确显示。作者提供了代码示例,并提示可能存在的跨域问题及解决思路,包括检查JavaScript控制台错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我想使用html2canvas获取屏幕截图。它工作正常的文本,但它不是呈现CDN图像,如果我托管图像在服务器中工作正常,但如果试图加载图像从CDN链接那些图像不呈现。html2canvas不呈现CDN图像

我的代码是:

的index.php

event-video

function capture() {

$('#target').html2canvas({

onrendered: function (canvas) {

var img = canvas.toDataURL();

console.log(img);

$('',{src:img}).appendTo($('img'));

//Set hidden field's value to image data (base-64 string)

$('#img_val').val(canvas.toDataURL("image/png"));

//Submit the form manually

document.getElementById("myForm").submit();

}

});

}

Save.php

//Get the base-64 string from data

$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);

//Decode the string

$unencodedData=base64_decode($filteredData);

echo $filteredData;

//Save the image

file_put_contents('img.png', $unencodedData);

?>

Save the image and show to user

Click Here to See The Image Saved to Server

Click Here to Go Back

Here is Client-sided image:

//Show the image

echo ''.%24_POST%5B'img_val'%5D.'';

?>

+0

更可能有一个跨域请求,在某个地方,这是被禁止的。检查您的JavaScript控制台是否有错误。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值