我试图使用 html2canvas 来捕捉谷歌地图的图像。它在 chrome 中被捕获是可以的,因为 Internet Explorer 不能。感谢任何可以帮助我的人。我已经解决了几天,
以下是代码:
function magic() {
var target = $('#map');
// if this is ie or other browser
if (isIE()) {
// is IE
html2canvas(target, {
useCORS: true,
logging: true,
onrendered: function(canvas) {
var data = canvas.toDataURL();
$("#img").attr("src", data);
var justTheData = data.replace(/^data:image\/(png|jpg);base64,/, "");//Removes everything up to ...'base64,'
document.getElementById("myImage").src="data:image/jpeg;base64," + justTheData;
}
});
} else {
// Other browser
html2canvas(target, {
useCORS: true,
logging: true,
onrendered: function(canvas) {
var data = canvas.toDataURL();
$("#img").attr("src", data);
window.open(data);
}
});
}
}
html代码:
<img id="myImage" src="">
Internet Explorer 的日志记录错误
html2canvas: Preload: Finding images
html2canvas: Preload: Done.
html2canvas: start: images: 1 / 1 (failed: 0)
Finished loading images: # 1 (failed: 0)
chrome的日志记录错误
Finished loading images: # 25 (failed: 0)