我有一个问题。在下面的代码中,当我将base64设置为src时,img.onload没有触发。但是当我将图像直接设置为src时,img.onload会被触发,而console.log会返回“image is loaded”。你能解释一下img.onload只有当它是一个图像而不是base64字符串时才会被触发的原因。另外,如何使base64字符串触发img.onload。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body style="background-color:#F5F5F6;">
</body>
<script>
(function() {
var b64 =
"data:image/svg+xml;base64,PGRpdiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94aHRtbCIgaWQ9ImdyYXBoMCIgc3R5bGU9IndpZHRoOiA4MDBweDsiPjxkaXYgaWQ9ImdyYXBoMF90aXRsZSIgc3R5bGU9InBvc2l0aW9uOiByZWxhdGl2ZTsgZGlzcGxheTogdGFibGU7IG1hcmdpbjogMHB4IGF1dG87IHBhZGRpbmc6IDEwcHg7IGZvbnQtc2l6ZTogMTBweDsgZm9udC1mYW1pbHk6IEFyaWFsLCBIZWx2ZXRpY2EsIHNhbnMtc2VyaWY7IGZvbnQtd2VpZ2h0OiBub3JtYWw7IGZvbnQtc3R5bGU6IG5vcm1hbDsgY29sb3I6IHJnYigwLCAwLCAwKTsiPlRpdGxlPC9kaXY+PGRpdiBpZD0iZ3JhcGgwX2NoYXJ0IiBkYXRhLWhpZ2hjaGFydHMtY2hhcnQ9IjUiIHN0eWxlPSJoZWlnaHQ6IDMwMHB4OyI+PGRpdiBpZD0iaGlnaGNoYXJ0cy03cDBmc2gyLTEwIiBjbGFzcz0iaGlnaGNoYXJ0cy1jb250YWluZXIgIiBzdHlsZT0icG9zaXRpb246IHJlbGF0aXZlOyBvdmVyZmxvdzogaGlkZGVuOyB3aWR0aDogODAwcHg7IGhlaWdodDogMzAwcHg7IHRleHQtYWxpZ246IGxlZnQ7IGxpbmUtaGVpZ2h0OiBub3JtYWw7IHotaW5kZXg6IDA7IC13ZWJraXQtdGFwLWhpZ2hsaWdodC1jb2xv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ZT0iZGlzcGxheTogdGFibGUtY2VsbDsgdmVydGljYWwtYWxpZ246IG1pZGRsZTsiPmYgLSBmb3VyPC9zcGFuPjwvZGl2PjxkaXYgaW5kZXg9IjMiIGlzcmV2ZWFsZWQ9InRydWUiIHN0eWxlPSJkaXNwbGF5OiB0YWJsZS1jZWxsOyI+PHNwYW4gc3R5bGU9ImRpc3BsYXk6IHRhYmxlLWNlbGw7IHdpZHRoOiAxOHB4OyBtYXJnaW4tcmlnaHQ6IDEwcHg7IHZlcnRpY2FsLWFsaWduOiBtaWRkbGU7IGJhY2tncm91bmQtY29sb3I6IHJnYigyNTUsIDEyNywgMCk7IGhlaWdodDogMTJweDsiPjwvc3Bhbj48c3BhbiBzdHlsZT0iZGlzcGxheTogdGFibGUtY2VsbDsgdmVydGljYWwtYWxpZ246IG1pZGRsZTsiPnQgLSB0d288L3NwYW4+PC9kaXY+PC9kaXY+PC9kaXY+PC9kaXY+PC9kaXY+";
function Jeff() {
var img = new Image();
document.body.appendChild(img);
img.setAttribute("src",b64);
img.onload = function() {
// document.getElementsByTagName("body")[0].appendChild(this);
console.log("image is loaded");
};
img.src = b64;
// img.src = "http://pierre.chachatelier.fr/programmation/images/mozodojo-original-image.jpg";
}
Jeff();
})();
</script>
</html>
谢谢。 Jeffrin。
答案 0 :(得分:3)
将svg的base64字符串设置为src
的{{1}}绝对可以正常工作。例如,尝试下面这个简单的base64 svg字符串:
img
看起来问题是你的svg是不正确的。从base64解码后,它周围有几个div(例如标题,图例)。如果您只是将图表svg本身并将其编码为base64,它将起作用:
https://jsfiddle.net/b7kru6e0/
您可以将其他组件作为html添加/附加。