1

Dear Stack Overflow,

I am trying to reference individual SVG graphics which reside in different SVG files via the tag and ID numbers in a master HTML5 page.

I want to be able to put onclicks on the use tags in the HTML page in order to make a multiple choice quiz (and then keep a score which I know how to do), The graphics are going to be bulky. Therefore, these need to be in an external svg files.

Here however, I have used a simple rectangle to make my question easier to follow

Here is my HTML

<html>
<head></head>

<body>

<svg>  
<use xlink:href="LINK.svg#link" />
</svg>
</body>
</html>

and here is My SVG

<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg">
<g id="link">
 <rect x="0" y="0" width="50" height="50" style="fill:red"/>
</g>
</svg>

This works exactly the way I want it to in Firefox and Opera. However, it does not work in Chrome or Safari. Not sure about Internet Explorer

Is there an alternative method that will allow me external access to the SVG data, and scripting from the main HTML page (because I want can keep a score over multiple SVG elements)

4

1 回答 1

0

您可以使用<object>标签访问您的 SVG。此链接向您展示如何从 html 到 SVG 编写脚本,反之亦然。

于 2013-02-07T22:10:43.847 回答