2016-11-12 6 views
0

"My Text"というテキストを含むSVG四角形を作成しました。 href属性(または他のもの)を使用して、別のPHPファイルにサイトをリダイレクトするために、テキスト "My Text"にクリック可能なリンクを追加したいと思います。 しかし、私は常に、テキストなしの「My Text」の矩形だけをリンクなしで取得します。href link from svg object

<?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>"; 
?> 

答えて

0

この時点では、この時点で(2016-11-12)ブラウザが一貫していません。今の

<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> 

使用し、最大クロスブラウザの互換性を確保するために、(:

<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> 

その他のみXML xlink:href構文を理解します:

一部の現代のブラウザでは(とすべきである)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 xlink:href="index.php> 
<a href="index.php">My Text</a> 
</a> 
</text> 
</svg> 

は、さらにXMLののxlinkについて読ん: - とSVG2でその廃止:

を参照してください:Mozilla Developer Network: xlink:href

関連する問題