Why is the onload event never fired in following snippet?
var img = new Image()
img.onload = function() {
alert("ok");
}
var svg = '<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>'
img.src = 'data:image/svg+xml;base64,'+ btoa(svg);
Link to jsfiddle: https://jsfiddle.net/venmmn3b/1/
Because it is NOT ok -
var img = new Image()
img.onload = function() {
console.log("ok");
}
img.onerror = function(e) {
console.log("Not ok",e);
}
var svg = '<svg></svg>';
img.src = 'data:image/svg+xml;base64,'+ btoa(svg);
I even tried to add valid svg:
var img = new Image()
img.onload = function() {
console.log("ok");
}
img.onerror = function(e) {
console.log("Not ok",e);
}
img.src = 'data:image/svg+xml;utf8,<svg><text font-size="68" font-weight="bold" font-family="DejaVu Sans" y="52" x="4" transform="scale(.8,1.7)"><tspan fill="#248">W3</tspan>C</text> <path fill="none" stroke="#490" stroke-width="12" d="m138 66 20 20 30-74"/></svg>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With