XML technologies / SVG / Adding hyperlinks and external files / Defining hyperlinks

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

SVG graphics can replace image maps or Flash animations only if hyperlinks can be defined. SVG provides the <a> tag for this. It roughly corresponds to HTML’s <a> tag and defines a hyperlink’s destination.

Note:
If the graphic is in a frameset, the hyperlink’s destination page opens in the current frame by default.

The hyperlink destination is defined by the attribute xlink:href, as the following example shows. An external image and its caption together form the hyperlink label, so both are enclosed in the <a> tag.

<?xml version="1.0" standalone="no"?>
...
<svg width="1000" height="800">
  <g transform="translate(0,0)">
    <a xlink:href="http://www.browser-bugs.de">
      <image x="10" y="10" xlink:href="mk.png" width="32" height="24" /> 
      <text x="40" y="30" style="font-size:12px;font-family:Arial;font-weight:bold">Browser-Bugs.de</text>
    </a>
  </g>
  <g transform="translate(0,30)">
    <a xlink:href="http://www.vmi-buch.de">
      <image x="10" y="10" xlink:href="mk.png" width="32" height="24" /> 
      <text x="40" y="30" style="font-size:12px;font-family:Arial;font-weight:bold">vmi-buch AG</text>
    </a>
  </g>
...
</svg>

Hyperlinks in SVG graphics are visually highlighted just like those in HTML pages. The following graphic, produced by the preceding listing, shows this.

Hyperlinks in SVG graphics

Figure: Hyperlinks in SVG graphics.

 

   

 

 

 

back to top