I got this error in safari while trying to convert svg to base64 url โโthrough code:
$svgCopy = $('svg').clone()
html = $('<div>').append($svgCopy).html()
imgSrc = 'data:image/svg+xml;base64,' + btoa(html)
imgEl.src = imgSrc
The problem is that when you set the attribute using NS (setAttributeNS), safari sets the NS \ d + namespace and does not set the xmlns: NS \ d + attribute in svg, so it looks like
<use NS1:href="#source" />
When you copy such an svg to Chrome, you have no such problem, because this svg element will look like this:
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#source" />
And as a result (on svg copy) we get an invalid file.
UPD: @Robert with setAttributeNSeverything ok:
el.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#source')
Without a proper call, it will not work in Chrome.
source
share