Generated SVG image doesn't display

javascript svg

714 просмотра

1 ответ

I'm developing a JavaScript class to show all SVG objects, but when I create the element "image", the browser doesn't display it. Though if I copy the generated code and put it in another document, the image is displayed.

When I searched the image using Firebug's inspector, the object appears but the image is not displayed.

I created the object using appendChild(), setAttribute() and setAttributeNS()

This is the generated code:

<svg xmlns="" xmlns:xlink="" height="100%" width="100%" >
<image width="50" height="50" xlink:href="logo.png" y="20" x="20" id="d"></image>

What I am doing wrong?

Автор: Alejandro Reyes Источник Размещён: 12.11.2019 10:01

Ответы (1)

1 плюс

The problem were the namespaces. This is the correct form to create images dynamically:

image.setAttributeNS('', 'xlink:href', 'flower.png');

More imformation can be found on MDN's 'Namespaces Crash Course'.

Автор: Alejandro Reyes Размещён: 29.10.2014 03:44
Вопросы из категории :