How can I link JavaScript to SVG?
I have a project that works with SVG and JS. Nowadays the SVG is responsible for calling the JS. In the middle of the SVG code there is an instruction like that:
planta30263.svg
<?xml version="1.0" encoding="UTF-8"?>
....
<script type="text/javascript" xlink:href="tatu1/svgEditarVisualizacao.js" xlink:actuate="onLoad" xlink:show="other" xlink:type="simple" />
.....
However sometimes it's necessary to change the directory from one 开发者_高级运维server to another. (tatu1 -> tatu2) So, I'd like to know if there is a way to make JS calls the SVG in the page which SVG is embedded, an external calling.
vis_rota.jsp
....
<embed src="<%=planta%>" id="plantaSVG" type="image/svg+xml" name="plantaSVG" />
....
The xlink:actuate, xlink:show and xlink:type attributes on the script element are not necessary, you can safely remove them.
It's better to use <object>
rather than <embed>
because then you can then provide fallback content if a browser lacks the ability to display svg, or if it has been disabled for any reason. For more information see the SVG Primer.
If you want to call functions from the svg to the document that referenced it, then see scripting between svg and html for some examples.
Not sure what you want and a plug but at iscriptdesign you can see some javascript manupulation to view different svg images. Adapt images online, and upload them using html 5's file api.
精彩评论