Insert HTML code inside SVG Text element

后端 未结 3 852
死守一世寂寞
死守一世寂寞 2020-11-30 08:51

I have an svg:text node, and I want to add HTML code inside it. Actually, my code is:



        
相关标签:
3条回答
  • 2020-11-30 09:06

    Why not use an SVG <a> element in this case? Don't forget that the href needs to be xlink:href though. E.g.

    <text x="10" y="54" text-anchor="start" class="barLegend"><a xlink:href='http://www.gmail.com'>Gmail</a></text>
    

    Only SVG animation elements, descriptive elements (<title> or <desc>), text content child elements (<tspan> or <textPath>) or the SVG <a> element are allowed as children of text elements.

    0 讨论(0)
  • 2020-11-30 09:14

    You have to use the foreignObject tag, for example:

    <foreignObject width="100" height="50"
                       requiredExtensions="http://example.com/SVGExtensions/EmbeddedXHTML">
      <body xmlns="http://www.w3.org/1999/xhtml">
        <a href='www.gmail.com'>Gmail</a>
      </body>
    </foreignObject>
    

    See also here http://www.w3.org/TR/SVG/extend.html and https://developer.mozilla.org/en/SVG/Element/foreignObject

    0 讨论(0)
  • 2020-11-30 09:16

    Another solution here is to put an event on the item and use javascript to open the target URL .. and not use the tag at all.

    0 讨论(0)
提交回复
热议问题