Re: SVG in HTML Questions


 I've updated my button test page (a study of SVG in HTML) again:

With a suggestion from Cameron and another from Erik, the two most
frustrating aspects of trying to use SVG buttons in HTML have been

1. Using SVG as a better PNG inside the HTML <a> tag.

 One must use <img> inside an <a> tag to use an SVG button otherwise the
SVG swallows mouse events (except with IE9). But <img> does not have a
fallback mechanism where a PNG can be used if SVG is not supported.
Cameron's suggestion to catch the error works quite nicely with IE8:

 <a href="" target="_blank">
   <img src="buttonA.svg" alt="A sample SVG button."

2. Reusing an (external) SVG button multiple times in the same HTML

 If one has an SVG button where the state is controlled by a JavaScript
function inside the SVG, in order to use the button multiple times in
the same HTML file one needs to be able to know which copy of the button
has been clicked. Erik's suggestion to use to get
the id of the object that references the SVG works quite well. This
technique has the additional benefit, that one can access the "color"
style property in the object via and
then use JavaScript to set the color of the background so different
buttons can have different colors (since currentColor doesn't work
across document boundaries).


PS. Did I mention that SMIL is a resource hog?

Received on Thursday, 24 February 2011 15:56:23 UTC