php - href link from svg object -


i created svg rectangle text "my text" in it. i'd add clickable link text "my text" using href attributes (or else) redirect site php file. but, rectangle text "my text" without link.

<?php    echo "<svg width='1100' height='1620'>";    echo "<rect x='450' y='30' width='200' height='30' style='fill:white stroke:black;stroke-width:2'></rect>";    $my_text = "my text";     echo "<text x='473'  y='51' font-family='verdana' font-size='18' fill='black' > <a href='index.php'>$my_text</a></text>";    echo "</svg>"; ?> 

at moment (2016-11-12) browsers not consistent on isssue.

certain contemporary browsers (and should) understand href:

<svg width="1100" height="1620"> <rect x="450" y="30" width="200" height="30" style="fill:white; stroke:black; stroke-width:2;"></rect> <text x="473" y="51" font-family="verdana" font-size="18" fill="black" > <a href="index.php">my text</a> </text> </svg> 

others understand xml xlink:href syntax:

<svg width="1100" height="1620"> <rect x="450" y="30" width="200" height="30" style="fill:white; stroke:black; stroke-width:2;"></rect> <text x="473" y="51" font-family="verdana" font-size="18" fill="black" > <a xlink:href="index.php">my text</a> </text> </svg> 

to ensure maximum cross-browser compatibility, use (for now):

<svg width="1100" height="1620"> <rect x="450" y="30" width="200" height="30" style="fill:white; stroke:black; stroke-width:2;"></rect> <text x="473" y="51" font-family="verdana" font-size="18" fill="black" > <a xlink:href="index.php> <a href="index.php">my text</a> </a> </text> </svg> 

further reading xml xlink: - , deprecation in svg2:

see: mozilla developer network: xlink:href


Comments

Popular posts from this blog

php - Autoloader issue not returning Class -

python - Getting next two indexes regardless of current index -

ruby - Prevent Custom Validation Error on Association -